Express app.set() Method

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

What you’ll learn

  • How to set app-level configuration with app.set(name, value).
  • How to retrieve values with app.get(name).
  • How app.set() relates to app.enable() and app.disable().
  • How to avoid common setting and environment mistakes.

Overview

app.set() is the core configuration API for storing and updating Express application settings.

App configuration

Set built-in options like view engine and views.

Custom settings

Store reusable app-level values for use across modules.

Foundation API

app.enable() and app.disable() are convenience wrappers around app.set().

Syntax

javascript
app.set(name, value)
  • name: setting key (for example view engine).
  • value: any value type (string, boolean, number, object).
  • Read later with app.get(name).
1

Set view engine and views path

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

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

Store and read custom config

javascript
app.set('supportEmail', 'support@codetofun.com');
app.set('featureFlagNewUI', true);

console.log(app.get('supportEmail'));
console.log(app.get('featureFlagNewUI'));

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

MethodPurposeExample
app.set(name, value)Set any value typeapp.set('etag', 'strong')
app.enable(name)Set boolean trueapp.enable('trust proxy')
app.disable(name)Set boolean falseapp.disable('x-powered-by')

🧪 Testing checklist

  • Set values and verify them with app.get(name).
  • Validate rendering setup after configuring view engine and views.
  • Test boolean settings using app.enabled() and app.disabled().
  • Check environment-specific overrides behave as expected.

Pitfalls to avoid

Setting key typos

Unexpected behavior

Small key mismatches lead to hard-to-track config bugs.

Mixed value types

Inconsistent reads

Keep setting value types predictable across environments.

Late configuration

Startup surprises

Set critical config before middleware/routes that depend on it.

❓ FAQ

It stores a setting value at the application level, which can later be read with app.get(name).
Common examples include view engine, views directory path, and various Express behavior settings.
app.enable(name) is shorthand for app.set(name, true), and app.disable(name) is shorthand for app.set(name, false).
Yes. You can store custom keys and values to share app-level configuration.
Use app.get(name) to retrieve the current value for that setting key.

Summary

  • Core use: app.set() stores application configuration values.
  • Flexibility: supports built-in and custom setting keys.
  • Practice: keep config explicit and verify values early at startup.
Did you know?

app.set(name, value) stores application-level configuration values such as view engine, views, or custom app settings.

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