Skip to content

Express.js Cheat Sheet

A single-page, comprehensive reference for the Express.js APIs, methods, and patterns covered throughout this course. Bookmark this page for quick lookups while building real applications.

How to Use This Cheat Sheet

Each table below groups a related set of Express APIs or conventions, application methods, routing, middleware types, request/response members, common third-party packages, and HTTP status codes, so you can jump straight to what you need.

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

app.use(express.json());
app.get('/users/:id', (req, res) => res.json({ id: req.params.id }));
app.listen(3000);

The five lines above touch nearly every category covered in the tables below: app creation, middleware, routing, parameters, and starting the server.

Quick Project Bootstrap

mkdir my-app && cd my-app
npm init -y
npm install express dotenv
npm install -D nodemon
  • This is the fastest path from an empty folder to a runnable Express project.
  • Add helmet, cors, and express-rate-limit immediately for any public-facing API.
  • Add express-validator or Joi as soon as routes accept client input.

Application Methods

Core methods on the app object.

Method Purpose
app.set(name, value) Store an app-wide setting
app.get(name) Read an app-wide setting
app.use([path], fn) Register middleware
app.METHOD(path, fn) Register a route for a given HTTP method
app.route(path) Chain multiple methods on one path
app.listen(port, cb) Start the HTTP server
app.locals Data shared across the app's lifetime

Routing Reference

The HTTP methods and path patterns you will use to define routes.

Pattern Example
Exact path app.get('/about', fn)
Route parameter app.get('/users/:id', fn)
Multiple parameters app.get('/users/:userId/posts/:postId', fn)
Optional parameter app.get('/products/:id?', fn)
Any method app.all('/status', fn)

Middleware Reference

Built-in and commonly installed middleware.

Middleware Purpose
express.json() Parse JSON request bodies
express.urlencoded({ extended: true }) Parse form-encoded bodies
express.static(dir) Serve static files
cors() Enable Cross-Origin Resource Sharing
helmet() Set secure HTTP headers
morgan('dev') Log HTTP requests
express-rate-limit Limit requests per client
multer() Handle multipart file uploads
cookie-parser Parse cookies into req.cookies
express-session Manage server-side sessions

req / res Reference

The most-used properties and methods on the request and response objects.

Member Description
req.params Named route segment values
req.query Query string values
req.body Parsed request body
req.headers Request headers
req.get(name) Read a single request header
res.status(code) Set the response status code
res.json(obj) Send a JSON response
res.send(body) Send a text/HTML response
res.redirect(url) Redirect the client
res.cookie(name, value, opts) Set a cookie

HTTP Status Code Reference

The status codes you'll use in almost every REST API.

Code Meaning Typical Use
200 OK Successful GET/PUT/PATCH
201 Created Successful POST that created a resource
204 No Content Successful DELETE with no response body
400 Bad Request Validation failure
401 Unauthorized Missing or invalid authentication
403 Forbidden Authenticated but not permitted
404 Not Found Resource does not exist
409 Conflict Duplicate or conflicting resource
429 Too Many Requests Rate limit exceeded
500 Internal Server Error Unexpected server-side error

Common Mistakes

  • Bookmarking a cheat sheet but never revisiting the deeper lessons behind each entry.
  • Copying a pattern from a table without understanding when it does or doesn't apply.
  • Skipping the security-related middleware rows when starting a new public-facing project.

Key Takeaways

  • This cheat sheet condenses the application, routing, middleware, req/res, and status code APIs covered throughout the course.
  • Use it as a quick lookup while building, not as a replacement for understanding the underlying concepts.
  • Security middleware (helmet, cors, rate limiting) belongs in nearly every production Express project.

Pro Tip

Keep this cheat sheet open in a browser tab while building your first few Express projects, over time you'll find yourself needing it less and less as the patterns become second nature.