Express app.enabled() Method
What you’ll learn
- How to check setting state using
app.enabled(name). - How
app.enabled()differs fromapp.enable()andapp.disable(). - How to build conditional startup logic based on settings.
- How to avoid mistakes when mixing state checks with state toggles.
Overview
app.enabled(name) is a read-only check that returns whether a given Express setting is currently on.
State inspection
Returns true/false for current setting status.
No config mutation
Unlike app.enable(), this method only reads existing state.
Great for conditions
Use in startup checks and environment-aware setup branches.
Syntax
javascript
app.enabled(name)- name: setting key, such as
trust proxy. - Returns
trueif enabled, otherwisefalse. - Read-only method; it does not modify app settings.
1
Basic check example
javascript
const express = require('express');
const app = express();
app.enable('trust proxy');
console.log(app.enabled('trust proxy')); // true
console.log(app.enabled('x-powered-by')); // depends on config2
Conditional behavior with app.enabled()
Branch setup logic based on current setting state.
javascript
const express = require('express');
const app = express();
app.enable('trust proxy');
if (app.enabled('trust proxy')) {
console.log('Proxy-aware behavior is active');
}📋 app.enabled() vs app.disabled()
| Method | Returns true when | Role |
|---|---|---|
app.enabled(name) | Setting is on | State check |
app.disabled(name) | Setting is off | State check |
🧪 Testing checklist
- Enable a setting and verify
app.enabled(name)returns true. - Disable the same setting and verify
app.enabled(name)returns false. - Compare with
app.disabled(name)to ensure opposite values. - Validate one conditional branch using enabled-state checks.
Pitfalls to avoid
Method confusion
Check vs toggle
app.enabled() reads state only; it does not enable settings.
Invalid setting key
Misleading results
Use exact setting names and avoid typos.
Assuming defaults
Environment inconsistency
Set and check settings explicitly across environments.
❓ FAQ
It checks whether a named Express application setting is enabled and returns a boolean.
app.enable(name) changes a setting to true, while app.enabled(name) only checks current state.
They are inverse checks for the same setting state.
Yes. It is useful for branching logic based on current app settings.
No. It is read-only and does not change configuration.
Summary
- Purpose:
app.enabled()checks whether an app setting is on. - Behavior: returns a boolean without mutating configuration.
- Usage: combine with enable/disable methods for predictable, testable app setup.
Did you know?
app.enabled(name) returns true when a setting is enabled and false when it is disabled.
4 people found this page helpful
