Express app.disabled() Method

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

What you’ll learn

  • How to read Express setting state using app.disabled(name).
  • How app.disabled() differs from app.disable() and app.enabled().
  • How to use setting checks for conditional behavior in app setup.
  • How to avoid confusion between state checks and state changes.

Overview

app.disabled(name) is a read-only check that tells you whether a given app setting is currently off.

State inspection

Returns true/false based on current setting value.

No mutation

Unlike app.disable(), this method never changes configuration.

Useful in setup logic

Great for branching app setup based on existing flags.

Syntax

javascript
app.disabled(name)
  • name: setting key, for example x-powered-by.
  • Returns true if the setting is disabled, otherwise false.
  • Read-only check method; it does not update app settings.
1

Basic check example

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

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

console.log(app.disabled('x-powered-by')); // true
console.log(app.disabled('etag')); // depends on current config
2

Conditional setup using app.disabled()

Inspect setting state and branch your startup behavior.

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

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

if (app.disabled('x-powered-by')) {
  console.log('Security header is hidden');
}

📋 app.disabled() vs app.enabled()

MethodReturns true whenRole
app.disabled(name)Setting is offState check
app.enabled(name)Setting is onState check

🧪 Testing checklist

  • Disable a setting and verify app.disabled(name) returns true.
  • Enable the same setting and verify app.disabled(name) returns false.
  • Compare output of app.enabled(name) and ensure values are complementary.
  • Use one conditional branch in setup and verify expected logs or behavior.

Pitfalls to avoid

Method confusion

State check vs state change

app.disabled() checks only; it does not disable anything.

Wrong setting name

Unexpected false/true values

Use valid setting keys and avoid typos.

Assuming default values

Inconsistent environments

Check state explicitly in each environment instead of assuming defaults.

❓ FAQ

It checks whether a named Express application setting is disabled and returns a boolean.
app.disable(name) changes a setting to false, while app.disabled(name) only checks the current state.
Yes. It is useful for conditional logging, environment checks, and feature toggles tied to app settings.
They are complementary checks. If app.disabled(name) is true, then app.enabled(name) is false.
No. It only reads the current state and does not mutate configuration.

Summary

  • Purpose: app.disabled() checks whether an app setting is turned off.
  • Behavior: returns a boolean and does not mutate configuration.
  • Usage: use it for conditional setup and diagnostics around app settings.
Did you know?

app.disabled(name) returns true when the setting is disabled and false otherwise.

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