Back to Interview Prep
Course progress0/12 chapters · 0%

Chapter 1 of 13

~10 min

Introduction to Express

Express is a minimal, unopinionated web framework built directly on top of Node’s http module. It takes the raw request/response handling Node already gives you and layers on routing, middleware, and a much friendlier API for building web servers and APIs.

What Express Actually Is

Node.js already ships a built-in http module capable of creating a server, but using it directly means manually parsing URLs, matching methods, reading request bodies, and setting response headers by hand for every single route. Express wraps that same http server with a thin, well-designed layer that handles routing, request parsing, and response helpers, without hiding Node underneath it - an Express app is still, at its core, an http.Server.

Because Express is deliberately minimal, it does not force a particular project structure, ORM, or templating engine on you the way a larger framework might. Instead, it gives you a small core (routing plus middleware) and lets the ecosystem of npm packages fill in everything else - body parsing, sessions, validation, database drivers - which is exactly why nearly every Node.js backend tutorial and countless production APIs are built on it.

Installing Express

Express is distributed as an ordinary npm package, so it is installed the same way as any other dependency, into an existing (or freshly initialized) Node.js project.

Setting up a new project with Express

npm init -y
npm install express

# package.json now lists express under "dependencies"

Creating and Starting Your First App

Calling the express() function returns an app object, which is the central piece of every Express program: you attach routes and middleware to it, then call app.listen() to start an underlying http server bound to a port. Everything else in Express - routing, middleware, error handling - is built around this single app object.

A minimal Express server

// server.js
const express = require('express');

const app = express();
const PORT = process.env.PORT || 3000;

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

app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});

// Run with: node server.js

How a Request Flows Through an Express App

When a request arrives, Express walks through the middleware and route handlers you registered, in the exact order they were added, until one of them sends a response (or an error is thrown). This ordered, pipeline-like flow is the foundation for everything else in the framework - routing is really just middleware that only runs for a matching method and path.

Coding Challenge

Create a minimal Express server that listens on port 3000 and responds to GET / with a plain-text greeting, and to GET /about with a short JSON object describing the app.

Answer every question below to mark this chapter as complete.

Quiz Yourself

Score: 0/4

1. What is Express, precisely?

2. What does calling express() return?

3. Why is Express described as "minimal" or "unopinionated"?

4. In what order does an incoming request pass through an Express app’s middleware and routes?

This is a free preview lesson. Sign up to unlock the full course.Sign up freeSign in