Express.js Documentation and Examples
repository·master·Indexed Apr 14, 2026
https://github.com/expressjs/expressOfficial repository for the Express.js web framework featuring historical changelogs, API references, and a collection of runnable example applications. Covers core capabilities like robust routing, HTTP helpers, and view systems supporting 14+ template engines. Includes practical guides for content negotiation, EJS configuration, static file serving, error handling middleware, and MVC architecture patterns.
What's inside expressjs/express
Usage
masterconst express = require('express'); const MyView = require('./my-view-engine'); const app = express(); // Override the default view constructor app.set('view', MyView); app.set('views', './views'); app.set('view engine', 'myengine'); app.get('/', (req, res) => { res.render('index'); }); app.listen(3000);This is useful when integrating custom view engines or modifying the default view behavior.
Sources:
History.mdDeprecate app.configure and req.auth
masterIn Express 3.13.0,
app.configureandreq.authwere deprecated. Developers should migrate to alternative patterns:- Replace
app.configurewith explicit environment checks or middleware setup. - Replace
req.authwith manual parsing of theAuthorizationheader or using thebasic-authmodule.
Deprecation warnings will be logged to the console when these methods are used.
Sources:
History.md- Replace
Use res.send for 205 responses
masterExpress now supports proper 205 (Reset Content) responses using
res.send. This is useful for scenarios where you need to instruct the client to reset the document view.Usage:
app.get('/reset', (req, res) => { res.send(205); // or res.status(205).send(); });This feature ensures compliance with HTTP standards for 205 responses.
res.send(205);Sources:
History.mdUse express.json and express.urlencoded parsers
masterExpress 4.16.0 introduced
express.jsonandexpress.urlencodedas built-in middleware for parsing request bodies. These replace the need for externalbody-parserpackage for basic JSON and URL-encoded data.Usage:
const express = require('express'); const app = express(); // Parse JSON bodies app.use(express.json()); // Parse URL-encoded bodies app.use(express.urlencoded({ extended: true })); app.post('/submit', (req, res) => { res.json(req.body); });These parsers are recommended for new applications and provide better integration with Express internals.
app.use(express.json()); app.use(express.urlencoded({ extended: true }));Sources:
History.mdUsage
masterEnsure your application is running on a version >= 3.5.3 to correctly parse IPv6 hosts.
const express = require('express'); const app = express(); app.get('/', (req, res) => { // Correctly returns [::1] or similar for IPv6 res.send(`Host: ${req.host}`); }); app.listen(3000);If you are upgrading from an older version, verify that
req.hostreturns the expected IPv6 format.Sources:
History.mdSupport SameSite=None in cookies
masterExpress 4.17.0 added support for
SameSite=Nonein cookies via thecookiedependency (v0.4.0). This is required for cookies to be sent in cross-site contexts.Usage:
res.cookie('session', 'value', { sameSite: 'none', secure: true });Note: When using
sameSite: 'none', you must also setsecure: truefor the cookie to be sent in modern browsers.res.cookie('session', 'value', { sameSite: 'none', secure: true });Sources:
History.mdInstall Express
masterHandle undefined in res.jsonp
masterExpress 4.17.2 fixed handling of
undefinedvalues inres.jsonp. Previously,undefinedvalues might have caused unexpected behavior or errors.Usage:
app.get('/data', (req, res) => { res.jsonp({ value: undefined }); // Now correctly handles undefined values });This ensures consistent behavior when serializing objects with undefined properties.
res.jsonp({ value: undefined });Sources:
History.mdAdd priority option to cookies
masterThe
cookiedependency (v0.5.0) added support for thepriorityoption in cookies. This allows you to specify the priority of the cookie (Low, Medium, High) which can affect how browsers handle cookie storage and transmission.Usage:
res.cookie('session', 'value', { priority: 'High' });Supported values are
'Low','Medium', and'High'. This feature is useful for managing cookie precedence in complex applications.res.cookie('session', 'value', { priority: 'High' });Sources:
History.mdConfigure json escape setting
masterThe
"json escape"setting can be enabled to automatically escape JSON output inres.jsonandres.jsonp. This is useful for preventing XSS attacks when rendering JSON in HTML contexts.Usage:
app.set('json escape', true); app.get('/data', (req, res) => { res.json({ message: '<script>alert("xss")</script>' }); // Output will be escaped: {"message":"\u003cscript\u003e..."} });Enable this setting when serving JSON that might be embedded in HTML to improve security.
app.set('json escape', true);Sources:
History.mdInstall Express
masterExpress is a fast, unopinionated, minimalist web framework for Node.js.