Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Const

views

The views application setting identifies the directory, or ordered directories, that Express uses to find view templates. It defaults to process.cwd() + '/views'.

How it works

The views application setting tells Express where templates are stored. It accepts one directory or an ordered list of directories; rendering searches that list in order, and its default is a views directory under the current working directory.

Syntax

app.set('views', path)
app.get('views')

Parameters

NameTypeDescription
nameStringApplication setting name, which must be views when reading or configuring this setting.

Returns

The configured value of the views application setting when read with app.get('views').

Key points

  • The setting can point to one template directory or provide several directories.
  • Its documented type is String | Array, and the default path is based on the current working directory.
  • An array establishes the lookup precedence: Express checks entries from first to last.
  • Mounted sub-applications inherit this setting from the parent application.

Common mistakes

  • Mounted sub-applications inherit the configured views value, so set it explicitly when a sub-app needs a different template directory.
  • With multiple directories, an earlier directory wins when more than one contains a matching view.

Example: Configure application view directories

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

app.set('views', [
  path.join(__dirname, 'views'),
  path.join(__dirname, 'shared-views')
]);

app.get('/', (req, res) => res.render('index'));

app.listen(3000);

Configures two view directories; Express searches them in array order when resolving a template.

When to use it

Custom template location

Store templates outside the conventional project directory.

Multiple template directories

Combine project templates with reusable templates from another directory.

Ordered fallback lookup

Control which duplicate template name takes precedence.

Interview questions

QWhat does the views setting control?

views is an Express application setting containing either a string directory or an array of directories. Its default is process.cwd() + '/views'.

Follow-up: What happens with an array? Express checks directories in their listed order and uses the first matching view.

QWhat types can the views setting have?

The setting accepts String | Array. A single string identifies one view directory; an array provides multiple lookup directories.

Follow-up: Why might an array be useful? It can combine application-specific templates with shared templates while preserving deterministic precedence.

QHow does Express search multiple view directories?

Express resolves templates against the configured view directories. When an array is used, lookup follows array order, so directory ordering affects which template is selected.

Follow-up: What related setting determines an extension when a rendered view omits one? view engine supplies the default template-engine extension.

  • app.set()
  • app.get()
  • view engine
  • res.render()

Source: Application Object · Express.js 4.x. Checked 2026-10-15.