Skip to content

Introduction to Express.js

Express.js is the most widely used web framework for Node.js. This introduction explains what Express is, why it exists on top of Node's built-in http module, and why it remains the default choice for building APIs and web servers in JavaScript.

What Is Express.js?

Express is a minimal, unopinionated web framework for Node.js. It was created by TJ Holowaychuk in 2010 and later donated to the OpenJS Foundation. Express does not force a particular project structure or set of tools, it simply gives you a thin, fast layer on top of Node's http module for routing, middleware, and request/response handling.

Instead of writing raw http.createServer() callbacks and manually parsing URLs, headers, and bodies, Express gives you a clean, chainable API: app.get(), app.post(), app.use(), and a req/res object with dozens of convenience methods already built in.

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello from Express!');
});

app.listen(3000, () => {
  console.log('Server listening on port 3000');
});

This entire program is a working web server. app.listen() starts an HTTP server, and any request to / is handled by the callback passed to app.get().

How Express Fits Into Node.js

Node.js (http module)
        |
        v
   Express (routing + middleware layer)
        |
        v
  Your route handlers, controllers, services
  • Express is a library you install with npm install express, not a separate runtime.
  • It wraps Node's http module so you rarely touch http.createServer() directly.
  • Everything in Express, routing, middleware, error handling, is built around a single request/response cycle.
  • Because it is unopinionated, Express is often paired with other libraries (Mongoose, Passport, Joi) rather than bundling them itself.

Express.js Quick Reference

The core pieces you will meet throughout this course, each covered in its own lesson.

Concept Example Purpose
Create app const app = express(); Creates an Express application instance
Route app.get('/path', handler) Handles a specific HTTP method and path
Middleware app.use(middleware) Runs logic for every matching request
Router express.Router() Groups related routes into a mountable module
Start server app.listen(port) Starts listening for HTTP requests
JSON body express.json() Parses JSON request bodies into req.body
Send response res.json(data) Sends a JSON response to the client

Why Express Was Created

Node.js ships with a low-level http module capable of building servers, but it requires manually parsing URLs, matching routes, reading request bodies as raw byte streams, and setting response headers by hand. As soon as an application needed more than one or two routes, developers were rewriting the same routing and parsing logic repeatedly.

Express solved this by providing a small, focused set of abstractions, routing methods, middleware, and a friendlier req/res API, without dictating how you structure the rest of your application.

  • Removes boilerplate URL parsing and routing logic.
  • Introduces the middleware pattern for composable request handling.
  • Stays intentionally small so you choose your own database, templating, and architecture.
  • Has one of the largest middleware ecosystems in the Node.js world.

Express 4 vs Express 5

Express 4 has been the stable, dominant version for years and is what most production apps and tutorials use. Express 5 became the default on npm in 2024 and cleans up long-deprecated APIs (like removing app.del() and built-in body-parserre-exports) while keeping the same core routing and middleware model.

For learning purposes, the concepts in this course, routing, middleware, req/res, are identical between the two versions; Express 5 mainly changes a few edge-case APIs and path-matching syntax (no more bare * wildcards, use named patterns instead).

Common Mistakes

  • Thinking Express is a full framework like Django or Rails; it is intentionally minimal and unopinionated.
  • Confusing Node.js (the runtime) with Express (a library that runs inside that runtime).
  • Assuming Express includes a database layer or templating engine by default, both are opt-in.
  • Installing an old Express 3.x tutorial's dependencies, which use APIs removed in modern Express.

Key Takeaways

  • Express is a minimal, unopinionated web framework built on top of Node's http module.
  • It was created by TJ Holowaychuk in 2010 and is now maintained under the OpenJS Foundation.
  • Its core value is routing plus a composable middleware pipeline.
  • Because it is unopinionated, you pair it with your own choice of database, validation, and templating libraries.

Pro Tip

Run npm ls express in an existing project before following any tutorial, so you know whether you are on Express 4 or 5 and can watch for the small API differences between them.