Express app.disable() Method

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 4 Code Examples
Express.js

What you’ll learn

  • How app.disable(name) changes Express app-level settings.
  • How to disable x-powered-by and other boolean settings correctly.
  • How to check setting state with app.enabled() and app.disabled().
  • When to use app.disable() vs app.set() in real projects.

Overview

Use app.disable() to turn off boolean Express settings at application level.

Short and explicit

app.disable(name) is clear intent for turning a flag off.

Security-focused use

Most common example: disable x-powered-by in production.

Works with settings API

Pair with app.enable(), app.set(), and app.get() for full control.

Syntax

javascript
app.disable(name)
  • name: setting key to disable, e.g. x-powered-by.
  • Equivalent to app.set(name, false).
  • Check with app.disabled(name) or app.enabled(name).
1

Basic usage

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

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

console.log(app.disabled('x-powered-by')); // true
2

Production-safe setup

A minimal production baseline with explicit setting toggles.

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

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

app.get('/', function (req, res) {
  res.send('Hello from Express');
});

📋 app.disable() vs app.set()

MethodPurposeExample
app.disable(name)Set boolean setting to falseapp.disable('x-powered-by')
app.set(name, value)Set setting to any valueapp.set('trust proxy', 1)

🧪 Testing checklist

  • Disable a setting and verify with app.disabled(name).
  • Send a response and inspect headers to confirm behavior (for example no X-Powered-By header).
  • Run in development and production mode to verify conditional setup logic.
  • Ensure other app settings still work as expected after toggling flags.

Pitfalls to avoid

Wrong setting key

No visible effect

Use exact setting names; typos silently disable the wrong key.

Environment mismatch

Unexpected behavior

Verify NODE_ENV when conditionally disabling settings.

Assuming request-level effect

Confusion in debugging

app.disable() changes app config, not route logic directly.

❓ FAQ

It sets a named Express application setting to false.
Yes. app.disable(name) is shorthand for app.set(name, false).
Use it in production to avoid exposing that your app uses Express via response headers.
Yes. Use app.enable(name) later to set the same flag to true again.
Not directly. It changes framework behavior tied to specific app settings.

Summary

  • Purpose: app.disable() turns a boolean app setting off.
  • Equivalent: it is shorthand for app.set(name, false).
  • Common practice: disable x-powered-by in production for cleaner headers.
Did you know?

app.disable(name) is equivalent to app.set(name, false) for Express application settings.

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.

4 people found this page helpful