Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Why does Nextjs offer an API folder when APIs can live on the back end?
1 point by akadeb on Jan 9, 2022 | hide | past | favorite | 2 comments
Does Nextjs make an app truly serverless by not requiring a backend? How would I connect to postgres database from the frontend directly?

I have a lot of business logic that needs to live on the backend



Because the `/pages/api` folder _lets_ you create a backend, very similar to any other web app server (ie, Express).

You are not _required_ to use that feature, but if you choose to use it, _that_ is where you'd do all your standard DB connections and returning JSON responses.


Nextjs is a backend application and runs its own http server.

You can connect to any database via a tunnel (cloudflare, ...) Or directly with certificate/credentials ( your DB server should allow only connection from the network where you host nextjs)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: