Express app.enable() Method

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

What you’ll learn

  • How app.enable(name) turns on Express app-level settings.
  • How to verify setting state using app.enabled() and app.disabled().
  • How to apply conditional setting logic by environment.
  • How to avoid confusion between setting toggles and checks.

Overview

app.enable() is the explicit way to turn a boolean Express setting on at application level.

Clear intent

app.enable(name) communicates exactly what setting behavior you want.

Complements disable

Use together with app.disable() when different environments need different defaults.

Settings-driven setup

Pair with app.enabled() and app.disabled() for robust startup logic.

Syntax

javascript
app.enable(name)
  • name: setting key to enable, for example trust proxy.
  • Equivalent to app.set(name, true).
  • Check state with app.enabled(name).
1

Basic enable example

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

app.enable('trust proxy');

console.log(app.enabled('trust proxy')); // true
2

Environment-based setting control

Enable or disable specific settings based on environment needs.

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

if (process.env.NODE_ENV === 'production') {
  app.enable('trust proxy');
} else {
  app.disable('trust proxy');
}

console.log('trust proxy enabled?', app.enabled('trust proxy'));

📋 app.enable() vs app.set()

MethodPurposeExample
app.enable(name)Set boolean setting to trueapp.enable('trust proxy')
app.set(name, value)Set any value typeapp.set('etag', 'strong')

🧪 Testing checklist

  • Enable a setting and verify app.enabled(name) returns true.
  • Check complementary state using app.disabled(name).
  • Test conditional setup under multiple NODE_ENV values.
  • Confirm dependent app behavior changes as expected when the setting is enabled.

Pitfalls to avoid

Wrong setting key

No effect

Typos in setting names cause confusing behavior checks.

Assuming defaults

Environment drift

Set values explicitly per environment to avoid hidden default differences.

Mixing check and toggle methods

Logic errors

Remember app.enable() changes state; app.enabled() only reads state.

❓ FAQ

It sets a named Express application setting to true.
Yes. app.enable(name) is shorthand for app.set(name, true).
Use it when you want explicit setting behavior, such as enabling trust proxy or etag in specific environments.
Use app.enabled(name), which returns true when the setting is currently on.
Yes. You can enable settings in one environment and disable them in another with conditional setup logic.

Summary

  • Purpose: app.enable() turns a boolean app setting on.
  • Equivalent: it is shorthand for app.set(name, true).
  • Practice: combine with enable/disable checks for explicit, environment-safe configuration.
Did you know?

app.enable(name) is equivalent to app.set(name, true) and turns on a boolean Express application setting.

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