Express.js app.enabled() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.enabled(name) returns true when an application setting is currently enabled (on / truthy). It is a read-only check — it never changes settings.

Use it after app.enable() (or instead of comparing app.get(name) === true). The opposite helper is app.disabled().

Syntax

Call app.enabled in your Express.js app. Start with this line.

Express
app.enabled(name)
CallWhat it does
app.enabled(name)Primary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

app.enabled(name)

Parameters

ParameterDescription
nameRequired. Setting to test — for example 'trust proxy' or 'x-powered-by'.
trueRequired. The setting is enabled (on / truthy).
falseRequired. The setting is not enabled (off / falsy).

Return Value

app.enabled(name) returns a Boolean: true if the setting is enabled (truthy), otherwise false. It does not change any setting.

Express
app.enable('trust proxy');
app.enabled('trust proxy'); // true
app.enabled('view cache');  // depends on NODE_ENV / prior sets

Express.js Examples

Example 1 — Official Check Pattern

Default is off for trust proxy; enable it, then confirm with app.enabled() (Express docs style).

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

console.log(app.enabled('trust proxy')); // false

app.enable('trust proxy');
console.log(app.enabled('trust proxy')); // true

app.listen(3000);

How It Works

  1. Check the default. trust proxy starts off, so app.enabled(...) is false.
  2. Turn the flag on. app.enable('trust proxy') stores true.
  3. Ask “is it enabled?” app.enabled(...) now returns true.
  4. Read-only. The check never mutates the setting.

Example 2 — Check x-powered-by

See the default (on), then disable and re-check with both helpers.

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

console.log(app.enabled('x-powered-by'));  // true (default)
console.log(app.get('x-powered-by'));      // true

app.disable('x-powered-by');
console.log(app.enabled('x-powered-by'));  // false
console.log(app.disabled('x-powered-by')); // true

app.listen(3000);

How It Works

  1. Default is on. Before changes, app.enabled('x-powered-by') is true.
  2. Raw value. app.get(...) shows the stored Boolean (true).
  3. Disable. app.disable(...) turns the flag off.
  4. Helpers agree. enabled becomes false; disabled becomes true.

Example 3 — Branch on enabled

Use the check in a status route to report production settings.

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

if (process.env.NODE_ENV === 'production') {
  app.enable('trust proxy');
  app.disable('x-powered-by');
}

app.get('/status', (req, res) => {
  res.json({
    trustProxyOn: app.enabled('trust proxy'),
    poweredByOn: app.enabled('x-powered-by')
  });
});

app.listen(3000);

How It Works

  1. Optional setup. Production enables trust proxy and hides X-Powered-By.
  2. Read in a route. app.enabled(...) reports each flag as JSON.
  3. Defaults elsewhere. Without production, trust proxy stays off and x-powered-by stays on.
  4. No mutation. The check only reads; it never flips the setting.

Runtime Support

app.enabled() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not call it.

✓ Server · Express 4 & 5

app.enabled()

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
app.enabled() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It returns true when a named application setting is currently enabled (truthy / on). It only reads the setting — it does not change it.
app.enable(name) turns the setting on. app.enabled(name) only checks whether it is currently on.
They are opposite checks. If app.enabled(name) is true, then app.disabled(name) is false for a Boolean setting.
Use app.enabled(name) when you want a clear yes/no “is it on?” answer. Use app.get(name) when you need the raw stored value.
No. It runs on your Express server in Node.js. Browsers only see the HTTP result of your app’s settings.

Next: app.engine()

Register a template engine for rendering views.

app.engine() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful