Express app.enabled() Method

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

What you’ll learn

  • How to check setting state using app.enabled(name).
  • How app.enabled() differs from app.enable() and app.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 true if enabled, otherwise false.
  • 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 config
2

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()

MethodReturns true whenRole
app.enabled(name)Setting is onState check
app.disabled(name)Setting is offState 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.

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