Express.js app.set() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

app.set(name, value) assigns an application setting. You can store any value; certain names (like views, view engine, trust proxy) configure Express itself.

Read settings with app.get(name) (one argument). For Booleans, app.set(name, true) equals app.enable(name), and false equals app.disable(name).

Syntax

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

Express
app.set(name, value)
app.get(name)                 // read setting
app.set(name, true)           // same as app.enable(name)
app.set(name, false)          // same as app.disable(name)
CallWhat it does
app.set(name, value)Primary signature.
app.get(name) // read settingRelated call form.
app.set(name, true) // same as app.enable(name)Related call form.
app.set(name, false) // same as app.disable(name)Related call form.

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.set(name, value)
app.get(name)                 // read setting
app.set(name, true)           // same as app.enable(name)
app.set(name, false)          // same as app.disable(name)

Parameters

ParameterDescription
nameRequired. Setting key — built-in (see table) or your own custom name.
valueRequired. Value to store. Type depends on the setting (string, boolean, number, function, …).

Return Value

app.set(name, value) returns the same application object (app), which is usually ignored. Use chaining only when it stays readable.

Express
app.set('view engine', 'ejs');
// => app

app.set('views', path.join(__dirname, 'views'))
  .set('view engine', 'ejs');

Express.js Examples

Example 1 — Custom Setting

Official-style: store any value, read it with app.get.

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

app.set('title', 'My Site');
console.log(app.get('title')); // "My Site"

app.get('/', (req, res) => {
  res.send(app.get('title'));
});

app.listen(3000);

How It Works

  1. Store. app.set('title', 'My Site') saves a custom key.
  2. Read. app.get('title') returns the string (settings overload).
  3. Route. app.get('/', …) is the routing overload — two arguments.
  4. Respond. The handler uses the stored title in the body.

Example 2 — Views + View Engine

Configure templates before res.render().

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

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.get('/', (req, res) => {
  res.render('home', { title: 'Hello' });
});

app.listen(3000);

How It Works

  1. views. Tells Express where template files live.
  2. view engine. Default extension so res.render('home') finds home.ejs.
  3. Engine package. Install/register the engine (EJS often needs only npm i ejs).
  4. Render. Route handlers call res.render using those settings.

Example 3 — Boolean Settings

set(true/false) matches enable / disable.

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

app.set('x-powered-by', false);   // same as app.disable('x-powered-by')
app.set('trust proxy', 1);        // trust first hop (only behind your proxy)

console.log(app.get('x-powered-by')); // false
console.log(app.enabled('trust proxy')); // true

app.get('/', (req, res) => {
  res.json({
    poweredByOff: app.get('x-powered-by') === false,
    ip: req.ip
  });
});

app.listen(3000);

How It Works

  1. Turn off header. x-powered-by: false hides Express branding.
  2. trust proxy. Number 1 trusts the first proxy hop — only if you own that proxy.
  3. Read flags. app.get / app.enabled confirm the state.
  4. Effect. Later middleware and req.ip respect trust proxy.

Runtime Support

app.set() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only see the effects (headers, rendered HTML).

✓ Server · Express 4 & 5

app.set()

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.set() Express on Node.js

Bottom line: Call app.set during startup, then verify with app.get(name).

Frequently Asked Questions

It assigns an application setting name to a value. Special names (views, view engine, trust proxy, and others) configure Express; custom names store any value you need.
Use app.get(name) with one argument. Note: app.get(path, handler) with two arguments registers a GET route — different overload.
app.set(name, true) is the same as app.enable(name). app.set(name, false) is the same as app.disable(name).
Settings with a default value are generally not inherited (you must set them on the sub-app). Settings with no default are inherited. Official exceptions: trust proxy is inherited; view cache is not inherited in production.
No. It is a server-side Express configuration method on Node.js.

Next: app.use()

Mount middleware, routers, and path prefixes.

app.use() 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