Express app.disabled() Method
What you’ll learn
- How to read Express setting state using
app.disabled(name). - How
app.disabled()differs fromapp.disable()andapp.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
trueif the setting is disabled, otherwisefalse. - 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 config2
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()
| Method | Returns true when | Role |
|---|---|---|
app.disabled(name) | Setting is off | State check |
app.enabled(name) | Setting is on | State 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.
4 people found this page helpful
