Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Module

app.set

Assigns a value to an Express application setting with app.set(name, value). Boolean settings can also be controlled through true or false.

How it works

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).

Syntax

app.set(name, value)

Parameters

NameTypeDescription
namestringThe application setting name, either a documented Express setting or a custom key.
valueanyThe value to assign to the setting.

Returns

The documentation describes the operation as setting an application value; it does not specify a return value.

Key points

  • Use app.get with the same setting name to read the value after assigning it.
  • The API supports Boolean application settings documented in the app settings table.
  • A built-in setting can accept a named subnet value, as shown by the trust proxy example.
  • Invoke set on the Express application object created by the framework.

Common mistakes

  • For Boolean settings, assigning false has the same effect as disabling the setting.
  • For Boolean settings, assigning true has the same effect as enabling the setting.

Example: Set and retrieve an application setting

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.

When to use it

Store custom configuration values

Application configuration

Enable or disable Boolean application settings

Feature flags

Configure trust proxy behavior

Reverse proxies

Interview questions

QWhat does app.set do?

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.

QHow does app.set behave with Boolean settings?

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.

QGive an example of a built-in setting configured with app.set.

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 proxy
  • app object

Source: Application Object · Express.js 4.x. Checked 2026-10-15.