Skip to content
Related Articles

Related Articles

Express.js | app.set() Function

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 10 Jun, 2020
Improve Article
Save Article

The app.set() function is used to assigns the setting name to value. You may store any value that you want, but certain names can be used to configure the behavior of the server.


app.set(name, value)

Installation of express module:

  1. You can visit the link to Install express module. You can install this package by using this command.
    npm install express
  2. After installing express module, you can check your express version in command prompt using the command.
    npm version express
  3. After that, you can just create a folder and add a file for example, index.js. To run this file you need to run the following command.
    node index.js

Filename: index.js

var express = require('express');
var app = express();
var PORT = 3000;
app.set('title', 'GeeksforGeeks');
app.get('/', (req, res) => {
app.listen(PORT, function(err){
    if (err) console.log(err);
    console.log("Server listening on PORT", PORT);

Steps to run the program:

  1. The project structure will look like this:
  2. Make sure you have installed express module using the following command:
    npm install express
  3. Run index.js file using below command:
    node index.js


    Server listening on PORT 3000
  4. Now open the browser and go to http://localhost:3000/, you will get the following output:

So this is how you can use the express app.set() function which assigns setting name to value.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!