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.

Runtime versus framework
QuestionNode.jsNext.js
What it isJavaScript runtimeReact framework
You install it asA program on the machineAn npm package in a project
Builds web pages?Only if you write that codeYes, with routing and rendering built in
Handles HTTP?With node:http or a library such as ExpressPages plus Route Handlers
Depends on the other?NoYes, minimum Node.js 20.9
Production startnode server.jsnext 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

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

  1. Click a layer, from the browser at the top to the operating system at the bottom.
  2. Read what that layer does in a Next.js app.
  3. Compare the plain Node.js server and the Next.js Route Handler examples further down.
  4. Use the decision rows in the table to pick what your project needs.

Tips

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.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap