Search code examples
next.jsserverless

Is nextJS backend serverless?


I am trying to understand NextJs. I understand that nextJs is a React Based framework. I also understand that NextJs has the functionality of creating a backend using nodeJS. Is this backend made up of serverless functions?


Solution

  • NextJS is a front-end framework at its core. The Node.js backend it creates is in support of its ability to perform SSR/ISR data fetching.

    When you say

    is this backend made up of serverless functions?

    I think you are referring to the NextJS pages/api directory, which provides an easy way to create API endpoints. While you can choose to treat these as serverless functions (Vercel, the creators of NextJS, provide an easy way to do this), you can also choose to have these API endpoints served any way you want, like by an Express server for example. To do this you would have code in your pages/api/<api-route-name>.js file that fetches data from another server. You can choose also to not use the pages/api directory at all and make your server calls how you normally would in a React app.

    You may also opt to customize NextJS routing/server behavior completely by using a custom server. While NextJS does provide an opinionated structure, you can really do whatever you want on the backend.