Reputation: 695
I know Next.js is front-end but when I used API of next.js it can response and can manage route or anything about back-end can do. Then I want to know "Next.js api is back-end ?"
Upvotes: 43
Views: 72568
Reputation: 153
NextJs can be used as a full-stack application. I used to work in a company in Berlin and our company was very big in 7 countries in Europe. We were using Nextjs as a full-stack software. In the back-end part, you need to take care of some functionalities yourself. For example, in NestJs we can manage DJ (inversion of control (IoC) ) but in NextJS you have to implement it by using and configuring the Inversify package yourself. You are also able to have the error handler, authentication, authorization and so on all in one code base which is great. I didn't see any limitations and we did a lot of complicated tasks by NextJS on the backend. We used a DDD structure which used different use-cases for a specific part of the domain logic and a centralized service for that domain part. This structure led to more flexible testing and the benefits of team working(4 different teams) on one single code base which I say again was great. I totally agree that the backend part of NextJS is not mature as as NestJS is but I believe it could be developed and it is flexible. You have to have good knowledge of NextJS's core and how it works and pay attention to which strategy is the best fit for you regarding caching, data fetching, and so on.
Upvotes: 0
Reputation: 1038
Dynamic Routing has two folders pages
or api
. To stay on the front-end or client-side put your JavaScript / React DOM code in pages
. The back-end or server-side of Next.js is with the api
folder. The api
JavaScript code is not executed in the browser but with Node.js so this is not safe for static page generation. When Next.js is hosted in the cloud with Vercel then your server-side JS will render, but on Netlify or other static hosts the api
folder will be ignored or throw errors. It's like running Express.js code in the browser the JIT rendered will fail
Next.js v13 transitioned React folders from pages
to app
and currently supports both folders. Before v13 the React client code was stored in pages
only.
Upvotes: 32
Reputation: 31
Next.js is primarily a front-end framework for building web applications, but it also includes an API functionality that allows developers to create server-side APIs. These APIs can handle requests, manage routing, and perform other server-side tasks that are typically associated with back-end development.
So, to answer the question: yes, it can be said that Next.js API is a back-end functionality, although it is closely integrated with the front-end development workflow.
Upvotes: 2
Reputation: 64
Yes. Next js is framework of React js. you can use it both like- frontend and backend. Thanks.
Upvotes: 2
Reputation: 112
I come from the asp.net world and am slowly, enjoying, learning javascript development. It does clash with me though when people describe something like Next.js, which I'm enjoying learning, as a backend.
To me it is more conceptually like an asp.net server-side frontend (Webforms, MVC, Razor Pages) etc. It seems its main concern is producing reactive frontend UI. Just because some of the frontend functionality runs/processed on server does NOT make it a backend AT ALL.
What about the fact it has api endpoints?
Well to me, a web api is only a means of enabling a frontend to talk to a backend across a network, the internet in this case. For me an api handles only very limited concerns; provides the endpoints, handles de/serialisation, talks http to the caller and that's kind of it, thin and dumb.
The backend doesn't really start till you get to your App layer and then the architectural fun can start, Application orchestration, Domain logic, dependency inverted data access layer etc. etc. all the things that talk to the complexity of designing robust software.
So much talk seems to be focused on where bits sit, is it on the client, is it on the server and less about the concern of what goes where.
I thing Next.js is an excellent server-side, frontend framework but whatever your onward stack into the backend, it's not a backend!
Upvotes: 1
Reputation: 49321
Next.js api provides REST API. We are sending requests internally to our next.api routes. With this you can add business logic in your next.js project without writing any additional custom server code and without configuring any api routes. In node.js app, we need to separete api code into controllers and routes, then register each route in express app, then you need to make sure that you registered the routes in correct order.
The only drawback as of now, vercel does not support websocket connections. So you cannot have realtime services. But you can kinda make it almost realtime with SWR. More on SWR Basically, with swr, you tell next.js to fetch data periodically, keep the response in cache and serve it.
With this feature, Next.js provides everything to build a full-stack application. So next.js also simplifies the backend for us.
Upvotes: 6
Reputation: 4873
Yes. Next.js is a pre-rendered React app in the client-side that users can view and interact with and can be considered as front-end. At the same time, it also does server-side rendering and API routes which can perform server-side code and access data in the database and can be considered as back-end.
Upvotes: 35