Next.js vs Node.js: How They Relate
Node.js is a runtime: the program that executes JavaScript on a server or your laptop. Next.js is a React framework for building websites, and its build tools and server run on Node.js. So the choice is rarely one or the other. Every Next.js app needs Node.js underneath, while a Node.js app need not involve Next.js.
| Question | Node.js | Next.js |
|---|---|---|
| What it is | JavaScript runtime | React framework |
| You install it as | A program on the machine | An npm package in a project |
| Builds web pages? | Only if you write that code | Yes, with routing and rendering built in |
| Handles HTTP? | With node:http or a library such as Express | Pages plus Route Handlers |
| Depends on the other? | No | Yes, minimum Node.js 20.9 |
| Production start | node server.js | next build, then next start |
Updated
The quickest way to see the relationship is to look at the layers a request passes through. Click each layer of a typical Next.js app below to see what it does and who is responsible for it.
The layers of a Next.js app
- Browser
- Your app code
- Next.js
- Node.js
- Operating system
Browser
Responsible: The visitor
Receives HTML that Next.js rendered on the server, then loads JavaScript only for Client Components so buttons and forms work.
The same response in plain Node.js and in Next.js
Plain Node.js server
Uses only the built-in node:http module. You decide the port, the headers and the routing yourself. Run it with node server.mjs.
// server.mjs
import { createServer } from "node:http";
const server = createServer((req, res) => {
if (req.url === "/api/hello") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello" }));
return;
}
res.writeHead(404).end();
});
server.listen(3000, () => console.log("http://localhost:3000"));Next.js Route Handler
The file path becomes /api/hello and Next.js runs the server. Unknown paths get the framework's 404 page automatically.
// app/api/hello/route.ts
export async function GET() {
return Response.json({ message: "Hello" });
}Where Node.js runs in a Next.js project
package.json scripts
Each script starts a Node.js process: the development server, the production build and the production server.
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
Node.js in one paragraph
The Node.js site calls it an asynchronous event-driven JavaScript runtime, designed to build scalable network applications. In practice it lets JavaScript read files, open network ports and talk to databases, which a browser does not allow.
What Next.js adds on top
Next.js turns a folder of React components into a site: file-based routes, server rendering, data fetching, image and font handling, and a production server. When you run next start, that server is a Node.js process, and the docs say this deployment supports every Next.js feature.
During development the same is true of next dev, and next build runs on Node.js to compile and prerender pages.
Choosing for a project
Building a website or web app with React? Use Next.js, and accept Node.js as part of the setup. Building a command line tool, a worker that processes a queue or a pure API? Write it for Node.js directly or with a backend framework, and skip Next.js entirely.
How it works
- Click a layer, from the browser at the top to the operating system at the bottom.
- Read what that layer does in a Next.js app.
- Compare the plain Node.js server and the Next.js Route Handler examples further down.
- Use the decision rows in the table to pick what your project needs.
Tips
- Check node --version before installing Next.js. The current docs list Node.js 20.9 as the minimum.
- Use a long-term support release of Node.js on servers, and pin the same major version locally and in production.
- If your project only serves an API with no web pages, a plain Node.js server or a backend framework is a lighter fit than Next.js.
- A static export of a Next.js site needs Node.js only at build time. The output is plain files any web server can host, at the cost of server-only features.
Frequently asked questions
Is Next.js a backend or a frontend?
Both, within limits. It renders React pages on the server, sends interactive parts to the browser and lets you write Route Handlers for JSON endpoints. It is not meant to be a full backend for many other clients.
Do I need to learn Node.js before Next.js?
You need Node.js installed and a feel for npm and the terminal. Deep knowledge of the node:http module is not required, because Next.js handles the server for you.
Does Next.js still have an Edge Runtime?
The runtime route option now lists 'nodejs' as the default and 'edge' as deprecated. The docs ask you to remove the runtime export from route files, so new code should assume Node.js.
Can I run Next.js with Bun or Deno?
The Next.js deployment docs list Bun as a verified adapter and Deno Deploy among other platforms with their own integration. Feature support varies outside the Node.js server, so check the platform's notes.
Is Express the same kind of thing as Next.js?
Closer than Node.js is, since both are libraries on top of Node.js. Express is a minimal HTTP server toolkit; Next.js is a full website framework built around React.
Related: Install Node.js and npm on a Mac, Next.js vs React, Express.js tutorial, NestJS vs Next.js, Next.js App Router.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- Next.js vs React: What Next Adds and When You Need It
- Nginx 502 Bad Gateway, and the Four Other Errors Nginx Throws Most
- nginx Load Balancing: upstream, Methods and Health Checks
- No-Code AI Agent Builder: A Buyer's Scorecard
- The Noindex Tag: Keep a Page Out of Google the Right Way
- Notion API Key: Create It, Share Pages, First Request
- npm: command not found and node Is Not Recognized
- npm Commands Cheat Sheet
Related guides
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App