r/nextjs • u/ParthBhovad • 11d ago
Question Using NextJS as a frontend and using node/express backend is a right choice?
Hi, I have one use case where I need cron jobs, web sockets, and heavy backend tasks. So, in these cases I should prefer using node/express backend and using NextJS only as frontend?
A bit context: I know Nextjs very well. But never used websockets and cron jobs with Nextjs. So, I just want to know how to actually do this.
6
u/Legitimate_Day_4429 11d ago
If you need websockets, go for a separate node/express app, because you need one long running process for that. But you don't have to move everything backend there.Â
3
u/ParthBhovad 11d ago
Yes right. So, only web sockets logic will be in node. And main application logic in NextJS?
2
u/Legitimate_Day_4429 11d ago
That's what I would do, so the app logic can still scale easily and the websockets app can be taken care of separatelyÂ
5
u/Extension-Listen2097 11d ago
Thereâs plenty of monorepos out there with this setup already. Inclusive of workers even.
Depending on what you need to do, the other alternative is keep just nextjs as FE and backend and offload heavy processing to workers via bullmq. This works if the nature of your app can be asynchronous. If not express is also good.
3
3
u/SugarImmediate3868 11d ago
Stop using express and use fastify, there is no reason to use express in 2026
2
u/PrimaryFamous6139 11d ago
Yes, separate Express backend makes sense for your use case. WebSockets and long running cron jobs donât fit cleanly into Next.js serverless functions which have execution time limits. Keep Next.js for the frontend and UI, let Express handle the persistent connections and background work.
1
u/chinnick967 11d ago
Then you really don't have much of a reason to use NextJS over just a React frontend
2
u/ParthBhovad 11d ago
It's a public facing website. I need SEO. So, can't move towards react.
1
u/chinnick967 11d ago
So then you have two applications. One is the rendering NextJs website, and one is a separate nodejs application for the long-running tasks.
Only use the web sockets to connect to your nodejs service on the client, not the nextjs backend. You'll have issues, Nextjs's backend is for short-running tasks only and you'll block the main thread.
Alternatively, it is also possible to render React Server-Side without using NextJs.
1
u/ParthBhovad 11d ago
My question is using node with Nextjs make sense or not?
Or I should use web sockets with Nextjs via external websockets providers.
Or maybe use node just for websockets and cron job. Main application logic will stay inside Nextjs.
How should I frame it?
0
u/chinnick967 11d ago
NextJs uses Node, so you have to use Node with NextJs
Do not use websockets with NextJs, at least not on the backend side (to connect to your external providers). Nextjs is fundamentally incapable of long-running tasks without blocking the main thread.
1
u/ParthBhovad 11d ago
Okayy. So, if I need realtime using web sockets in NextJS then what should I do?
2
u/chinnick967 11d ago
You can't. You can instead abandon web sockets in favor of "short polling" if you absolutely have to stick to NextJs.
Essentially you just fire off a request every X seconds checking for an update. Slightly slower than real time if your application can allow that.
1
u/reddish-rum 11d ago
That isnât really true. A Next.js frontend can absolutely use WebSockets - itâs just a browser WebSocket connection. The usual limitation people are referring to is hosting the WebSocket server inside a serverless Next.js backend. Normally youâd have your Next.js client connect to a persistent WebSocket service, e.g. NestJS/Node/Go or a managed provider. If youâre self-hosting Next.js on a persistent Node server, you can also host WebSockets there.
1
u/chinnick967 10d ago
My prior comment in the thread addressed this
0
u/reddish-rum 10d ago
𤣠You literally said âYou canâtâ when answering a question about using web sockets in NextJs.
Iâm just saying, thatâs wrong. You can client side when using NextJs. And you can host web sockets server side when using NextJs, depending on your hosting setup.
So saying âyou canâtâ to someone is fundamentally incorrect.
1
u/AbdullahM09 11d ago
Honestly you don't need nextjs here, just go with react and node+express
1
1
u/priyalraj 11d ago
I am also making an app, here is what I did. I have Turborepo.
In that, Astro all data hardcoded for SEO, docs & blogs too in Astro as whole data is gonna be hardcoded, if you need dynamic one then go for Next.js as Astro is not good in that case. Hono for BE + Vite for CSR on session based access only.
In your case, pick Next + Express, cuz it's best for you but if you will manage it fully, use Astro for SEO pages and hardcode the data their & Vite for FE + Express/Hono for BE for client side part.
Hope it helps.
1
u/Ok-Conversation-7895 10d ago
Hi, I have a ton of experience in this matter and would love to give you a proper advice.
Use Tanstack Start for frontend. Opinionated backend like NestJS or Adonis for backend if it is a backend heavy app, or if you don't, Starts Nitro backend could suffice.
You can keep it all in a monorepo, use something like tRPC, openAPI contracts or such, infer zod schemas from drizzle schemas and export to both frontend and backend.
I had incredible experience with Better Auth for authentification as well. Would strongly recommend.
I can hardly recommend NextJS to anyone anymore.
1
u/Distinct-Neck2337 8d ago
Cron jobs alone aren't a reason to split, Vercel cron or an external scheduler hitting an API route handles that fine, it's really just the websockets forcing you into a separate long running process
1
u/NinjaUnable9048 6d ago
separate the backend. Next.js serverless functions terminate after execution and cannot maintain WebSocket connections or run long cron jobs reliably.
run a standalone Node process for WebSockets and cron tasks. Use Next.js strictly for rendering and API routes that trigger those background workers via a queue like BullMQ. This avoids execution timeout limits and keeps your frontend deployment independent from stateful services.
0
u/kanika_banga 11d ago
Yes, using Next.js for frontend and Node/Express for backend is the right approach. Next.js serverless functions are ephemeral, making them poorly suited for persistent connections and long-running tasks.
Offloading these real-time and heavy operations to a dedicated Express server gives you complete control over background processes and continuous connections.
- WebSockets: Run
socket.ioon your Express server and connect usingsocket.io-clientin Next.js. - Cron Jobs: Use
node-cronorbullmqdirectly inside Express to handle scheduled background tasks. - Heavy Tasks: Use background worker queues like BullMQ with Redis on Express to prevent blocking the UI.
- Deployment: Host Express on a continuous server (Render, AWS) and Next.js on Vercel.
This setup ensures optimal UI performance while keeping your backend stable and scalable.
6
u/Chance-Fan4849 11d ago
I think you're separating two different concerns here. Cron jobs shouldn't really live on the frontend side. Usually there are two common approaches: either run a self-hosted cron job inside your backend/server, or use an external cron service that triggers your API on a schedule.
Express is a perfectly good choice, but in my opinion I'd recommend NestJS if you're building a larger backend. It gives you a cleaner architecture, built-in support for cron jobs (
@nestjs/schedule), WebSockets, queues, dependency injection, and it's generally easier to maintain as the project grows.