I just came across some discussions claiming that using Next.js for backend development is a poor choice. I've already built a web app with a full stack using Next.js, and I'm now sitting at about 15,000 lines of code. Is it really worth the trouble to refactor and separate the backend? If so, what are some recommended alternatives? Thanks in advance!
4 Answers
Honestly, I think Next.js adds unnecessary complexity for backend roles. It feels like a push to keep you tied to Vercel’s ecosystem. If you want to keep it simple, there are better alternatives out there.
Next.js does have some advantages, like allowing for code sharing and reducing duplication. It really boils down to your needs and team size. I’m on a four-person team in a startup using Next.js for various frontend pages, webhooks, and API endpoints. We’re moving away from a lot of scattered lambdas to consolidate everything, and so far, it’s working fine. Personally, I like SPAs better, but Next.js has proven itself useful for us. Just keep in mind that if your app won't ever have frontend pages, you might be better off sticking with something like Express or Go.
While Next.js isn’t your traditional backend framework, some people use it in a BFF capacity. Just be aware that it may not fit every use case.
You can set up some BFF (Backend for Frontend) routes with Next.js, and they work okay. However, we eventually found that having a dedicated backend hosted separately scaled much better. Nowadays, we run our frontend on Next.js and keep our backend on a different service.
You can actually self-host Next.js if needed. You can deploy it as a Node.js server, in a Docker container, or even do a static export. Check their documentation for more on deploying options!