Store custom configuration values
Application configuration
Express.js · Module
Assigns a value to an Express application setting with app.set(name, value). Boolean settings can also be controlled through true or false.
Call app.set(name, value) to assign an application setting. Boolean settings can be enabled or disabled through true or false, and the stored value can be read later with app.get(name).
app.set(name, value)| Name | Type | Description |
|---|---|---|
name | string | The application setting name, either a documented Express setting or a custom key. |
value | any | The value to assign to the setting. |
The documentation describes the operation as setting an application value; it does not specify a return value.
const express = require('express');
const app = express();
app.set('title', 'My Site');
console.log(app.get('title')); // My Site
app.get('/', (req, res) => res.send(app.get('title')));
app.listen(3000);Creates an Express app, stores a custom setting, reads it back, and uses it in a route.
Application configuration
Feature flags
Reverse proxies
app.set(name, value) assigns a value to an application setting. The setting may be built in, such as trust proxy, or a custom application property.
Follow-up: How can the value be read? Use app.get(name), which retrieves the current value of the setting.
For Boolean application properties, app.set(name, true) is equivalent to app.enable(name), while false is equivalent to app.disable(name).
Follow-up: What should be used for a non-Boolean custom value? Pass that value directly to app.set and retrieve it with app.get.
The trust proxy setting can be configured with app.set, for example using the loopback subnet. This setting changes how Express derives proxy-related request information.
Follow-up: What request properties are affected? The documentation identifies req.hostname, req.protocol, req.ip, and req.ips.
app.get()app.enable()app.disable()trust proxyapp object