Node.js (Express)

JavaScript on the server — one language for everything.

What is it?

Node.js is a runtime that lets JavaScript — the language of the browser — run on a server. That means the same language you use for frontend interactivity can also handle requests, talk to databases, and build APIs. Express is the most popular Node web framework: a thin, flexible layer that maps URLs to functions and handles the request/response details.

Together they power one of the largest developer ecosystems in the world. npm, Node's package registry, has a library for nearly anything you'll ever want to do.


When to use it

Node + Express is the natural backend if you're already learning JavaScript for the frontend — one language across the whole stack, and it pairs seamlessly with React or Vue. It's especially good for APIs and real-time apps. It needs a VPS or platform service (it won't run on classic shared hosting, where PHP wins), and if you'd rather learn the most readable language first, Python + Flask is the gentler start.


Core concepts
  • npm and package.json — every project declares its dependencies in package.json; npm install fetches them into node_modules.
  • Routes — Express maps an HTTP method and URL to a handler function: app.get("/users", handler).
  • Middleware — functions that run on every request before your handler: parsing JSON, logging, checking logins. Express is essentially a middleware pipeline.
  • Async by design — Node never waits idle. Slow operations (database calls, file reads) use async/await so the server keeps handling other requests meanwhile. This is Node's superpower and the biggest beginner hurdle.
  • JSON APIs — most Node backends serve JSON to a JavaScript frontend rather than rendering HTML themselves.

A taste of the code
import express from "express";

const app = express();
app.use(express.json());

app.get("/api/hello", (req, res) => {
  res.json({ message: "Hello from Express!" });
});

app.listen(3000, () => console.log("Running on port 3000"));

Run node server.js and you have a JSON API at localhost:3000/api/hello — ready for a React or Vue frontend to fetch from.


Your first steps
  1. Be solid on JavaScript fundamentals — especially functions, objects, and promises/async.
  2. Install Node.js (the LTS version), then run npm init -y and npm install express in a new folder.
  3. Copy the server above, run it, and hit the endpoint in your browser.
  4. Build a small REST API — a todo API with GET, POST, and DELETE routes storing data in an array.
  5. Swap the array for a real database like SQLite or PostgreSQL, then connect a frontend to it.

← Back to Stack Picker All primers