Express.js app.disable() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.disable(name) turns a Boolean application setting off by setting it to false. It is the readable shorthand for app.set(name, false).

Common uses include hiding the X-Powered-By header with app.disable('x-powered-by'), or turning off trust proxy. Pair it with app.disabled() to check the flag, and app.enable() to turn it back on.

Syntax

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

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

Parameters

ParameterDescription
nameRequired. Boolean setting to turn off — for example 'x-powered-by' or 'trust proxy'.

Return Value

app.disable(name) is equivalent to app.set(name, false). It returns the same application object (app), which is usually ignored.

Express
app.disable('x-powered-by');
// => app (same instance)

app.disable('etag').set('title', 'Docs'); // chaining works

Express.js Examples

Example 1 — Hide X-Powered-By

Turn off the default Express branding header.

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

app.disable('x-powered-by');

app.get('/', (req, res) => {
  res.send('Hello');
});

app.listen(3000);

How It Works

  1. Create the app. Settings apply to this Express instance.
  2. Disable early. app.disable('x-powered-by') sets the flag to false before requests arrive.
  3. Serve as usual. Routes still work; only the header behavior changes.
  4. Inspect responses. Clients no longer see X-Powered-By: Express.

Example 2 — Disable and Confirm

Match the official pattern: disable a setting, then read it with app.get / app.disabled.

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

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

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

app.listen(3000);

How It Works

  1. Turn it on first. app.enable('trust proxy') sets the flag to true so the change is visible (default is already off).
  2. Disable it. app.disable('trust proxy') is the same as app.set('trust proxy', false).
  3. Read the raw value. app.get('trust proxy') returns false.
  4. Confirm with helpers. app.disabled(...) is true; app.enabled(...) is false.

Example 3 — Production Toggles

Disable a couple of settings only when NODE_ENV is production.

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

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

app.get('/', (req, res) => {
  res.json({
    poweredByOff: app.disabled('x-powered-by'),
    etagOff: app.disabled('etag')
  });
});

app.listen(3000);

How It Works

  1. Gate on environment. Only production runs the disable calls.
  2. Turn two flags off. x-powered-by and etag become false.
  3. Expose the state. The JSON route reports app.disabled(...) for each.
  4. Dev stays default. Without NODE_ENV=production, those settings keep Express defaults.

Runtime Support

app.disable() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not call it — they only see the resulting HTTP behavior.

✓ Server · Express 4 & 5

app.disable()

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.disable() 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 sets a named Boolean application setting to false. It is the same as calling app.set(name, false) for that setting.
To stop Express from sending the X-Powered-By: Express response header, which is a common production hardening step.
Use app.disabled(name), which returns true when the setting is false. You can also read the raw value with app.get(name).
Yes. Call app.enable(name), which is the same as app.set(name, true).
No. It configures your Express server on Node.js. Browsers only receive the resulting HTTP behavior.

Next: app.disabled()

Check whether a Boolean Express setting is currently off.

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