What is Express?

Express is a fast, minimalist web framework for building servers and APIs with Node.js.

Express is the most popular web framework for Node.js. Node.js lets you run JavaScript on a server, but on its own it only gives you low-level building blocks. Express adds a thin, friendly layer on top so you can build web servers and APIs quickly.

What Express gives you

  • Routing — map URLs and HTTP methods to code.
  • Middleware — run functions on every request (logging, parsing, auth).
  • Request & response helpers — read the body, send JSON, set status codes.
  • Views — render HTML with template engines.

Express is called unopinionated because it does not force a folder layout or database on you. You assemble the pieces you need.

Example

Example · javascript
const express = require('express');
const app = express();

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

app.listen(3000);

When to use it

  • A startup uses Express to build a REST API backend that their React frontend consumes to fetch product listings.
  • A developer scaffolds an Express server in under 5 minutes to prototype a webhook receiver for a payment provider.
  • A team picks Express over raw Node.js http module to avoid manually parsing URL paths and HTTP methods in every route.

More examples

Minimal Express server

Shows the smallest possible Express server: import the module, create an app, register one GET route, and start listening.

Example · js
const express = require('express');
const app = express();

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

app.listen(3000);

Express vs raw Node http

Contrasts boilerplate-heavy raw Node HTTP with Express's declarative, chainable routing API.

Example · js
// Raw Node — manual routing
const http = require('http');
http.createServer((req, res) => {
  if (req.method === 'GET' && req.url === '/') {
    res.end('Hello');
  }
}).listen(3000);

// Express — declarative routing
const express = require('express');
express().get('/', (req, res) => res.send('Hello')).listen(3000);

JSON API endpoint

Demonstrates Express returning a structured JSON response — the most common use-case for a REST API.

Example · js
const express = require('express');
const app = express();

app.get('/api/status', (req, res) => {
  res.json({ status: 'ok', version: '1.0.0' });
});

app.listen(3000, () => console.log('API ready on port 3000'));

Discussion

  • Be the first to comment on this lesson.