Express.js – app.disable() Method


The app.disable() method disables the setting name passed in the function. This method sets the setting name to False. We can perform the same function by using the app.set() method too, by passing its value as False.

Syntax

app.disable(name)

Example 1

Create a file with the name "appDisable.js" and copy the following code snippet. After creating the file, use the command "node appDisable.js" to run this code.

// app.disable() Method Demo Example

// Importing the express module
const express = require('express');

// Initializing the express and port number
var app = express();

// Initializing the router from express
var router = express.Router();
var PORT = 3000;

// Disabling the property foo
app.disable('foo');

// Checking the foo property
console.log(app.get('foo'));

Output

C:\home
ode>> node appDisable.js false

Example 2

Let’s take a look at one more example.

// app.disable() Method Demo Example

// Importing the express module
const express = require('express');

// Initializing the express and port number
var app = express();

// Initializing the router from express
var router = express.Router();
var PORT = 3000;

// Disabling the property foo
app.disable('trust proxy');

// Checking the foo property
console.log("Trust proxy settings are set to: ", app.get('trust
proxy'));

Output

C:\home
ode>> node appDisable.js Trust proxy settings are set to: false

Updated on: 30-Sep-2021

476 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements