Express.js app.enable() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.enable(name) turns a Boolean application setting on by setting it to true. It is the readable shorthand for app.set(name, true).

A common case is app.enable('trust proxy') when you sit behind a reverse proxy. Pair it with app.enabled() to confirm, and app.disable() to turn the flag off again.

Syntax

Call app.enable in your Express.js app. Start with this line.

Express
app.enable(name)
CallWhat it does
app.enable(name)Primary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

app.enable(name)

Parameters

ParameterDescription
nameRequired. Boolean setting to turn on — for example 'trust proxy' or 'x-powered-by'.

Return Value

app.enable(name) is equivalent to app.set(name, true). It returns the same application object (app), which is usually ignored.

Express
app.enable('trust proxy');
// => app (same instance)

app.enable('case sensitive routing').get('/Users', handler);

Express.js Examples

Example 1 — Enable trust proxy

Turn on proxy trust so Express reads X-Forwarded-* headers (official-style usage).

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

app.enable('trust proxy');

app.get('/', (req, res) => {
  res.json({ ip: req.ip, secure: req.secure });
});

app.listen(3000);

How It Works

  1. Create the app. Settings apply to this Express instance.
  2. Enable early. app.enable('trust proxy') sets the flag to true before requests arrive.
  3. Read request helpers. req.ip and req.secure can use forwarded headers.
  4. Only behind a trusted proxy. Do not enable this on a public internet-facing process with no proxy.

Example 2 — Enable and Confirm

Show that app.enable matches app.set(..., true), then read it back.

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

app.enable('trust proxy');

console.log(app.get('trust proxy'));    // true
console.log(app.enabled('trust proxy'));  // true
console.log(app.disabled('trust proxy')); // false

app.listen(3000);

How It Works

  1. Turn the flag on. app.enable('trust proxy') stores true (same as app.set('trust proxy', true)).
  2. Read the raw value. app.get('trust proxy') returns true.
  3. Ask “is it enabled?” app.enabled(...) is true.
  4. Ask “is it disabled?” app.disabled(...) is the opposite check.

Example 3 — Environment Toggle

Enable trust proxy only in production, keep defaults elsewhere.

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

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

app.get('/status', (req, res) => {
  res.json({
    trustProxyOn: app.enabled('trust proxy'),
    poweredByOn: app.enabled('x-powered-by')
  });
});

app.listen(3000);

How It Works

  1. Gate on environment. Only production calls app.enable('trust proxy').
  2. Leave other defaults. x-powered-by stays on unless you disable it.
  3. Expose the state. The status route reports app.enabled(...) for each flag.
  4. Dev stays simple. Without production, trust proxy remains off (Express default).

Runtime Support

app.enable() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not call it — they only see the resulting HTTP behavior.

✓ Server · Express 4 & 5

app.enable()

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
app.enable() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It sets a named Boolean application setting to true. It is the same as calling app.set(name, true) for that setting.
When your app sits behind a reverse proxy and you want Express to trust X-Forwarded-* headers for the client IP and protocol.
Use app.enabled(name), which returns true when the setting is on. You can also read the raw value with app.get(name).
Yes. Call app.disable(name), which is the same as app.set(name, false).
No. It configures your Express server on Node.js. Browsers only receive the resulting HTTP behavior.

Next: app.enabled()

Check whether a Boolean Express setting is currently on.

app.enabled() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful