Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for building web and mobile applications. It sits atop Node.js as a de facto standard server framework for REST APIs, web applications, and microservices. Express 5 (released October 2024) modernizes the framework by requiring Node.js 18+, automatically forwarding rejected promises to error handlers, tightening route-pattern security via path-to-regexp v8, and adding native Brotli compression support. Understanding middleware execution order, asynchronous error handling patterns, and the request-response lifecycle is essential for leveraging Express effectively in production.
What This Cheat Sheet Covers
This topic spans 28 focused tables and 197 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Application Methods
| Method | Example | Description |
|---|---|---|
app.listen(3000, () => console.log('Server running')) | Starts the Express application and binds it to a specified port, listening for incoming HTTP requests. | |
app.use(express.json())app.use('/api', routes) | • Mounts middleware functions at a specified path • executes for every request matching that path, or globally if no path specified. | |
app.set('view engine', 'ejs')app.set('port', 3000) | • Assigns a configuration setting to a name • used for application-level settings like template engine or custom properties. | |
const port = app.get('port') | Retrieves the value of a setting previously assigned with app.set(). | |
app.locals.title = 'My App' | Object containing application-level variables accessible throughout the app's lifecycle, including inside templates. |