Express.js app.disabled() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.disabled(name) returns true when a Boolean application setting is currently false (off). It is a read-only check — it never changes settings.

Use it after app.disable() (or instead of comparing app.get(name) === false). The opposite helper is app.enabled().

Syntax

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

Express
app.disabled(name)
CallWhat it does
app.disabled(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.disabled(name)

Parameters

ParameterDescription
nameRequired. Boolean setting to test — for example 'trust proxy' or 'x-powered-by'.
trueRequired. The setting value is false (disabled).
falseRequired. The setting is not disabled (enabled / truthy).

Return Value

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

Express
app.disable('x-powered-by');
app.disabled('x-powered-by'); // true
app.disabled('etag');         // false when etag is still enabled

Express.js Examples

Example 1 — Official Check Pattern

Disable a setting, then confirm with app.disabled() (same idea as the Express docs).

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

app.disable('trust proxy');
console.log(app.disabled('trust proxy')); // true

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

app.listen(3000);

How It Works

  1. Turn the flag off. app.disable('trust proxy') stores false.
  2. Ask “is it disabled?” app.disabled(...) returns true.
  3. Turn it back on. app.enable('trust proxy') stores true.
  4. Ask again. Now app.disabled(...) returns false.

Example 2 — Check x-powered-by

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

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

console.log(app.disabled('x-powered-by')); // false (default is on)
console.log(app.get('x-powered-by'));      // true

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

app.listen(3000);

How It Works

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

Example 3 — Branch on disabled

Use the check in a status route so ops can confirm production hardening.

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

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

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

app.listen(3000);

How It Works

  1. Optional disable. Production turns x-powered-by off.
  2. Default trust proxy. Stays off unless you enable it — so trustProxyOff is usually true.
  3. Read in a route. app.disabled(...) reports current state as JSON.
  4. No mutation. The check only reads; it never flips the setting.

Runtime Support

app.disabled() 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.disabled()

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.disabled() 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 Boolean application setting is false (disabled). It only reads the setting — it does not change it.
app.disable(name) turns the setting off. app.disabled(name) only checks whether it is currently off.
They are opposite checks. If app.disabled(name) is true, then app.enabled(name) is false for a Boolean setting.
Use app.disabled(name) when you want a clear yes/no “is it off?” 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.enable()

Turn a Boolean Express application setting on.

app.enable() 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