Express.js – app.disabled() Method


The app.disabled() method checks and returns True if the property name passed is set to False or is disabled. If not, we can disable the property by using the app.disable() method.

Syntax

app.disabled( name )

Example 1

Create a file with the name "appDisabled.js" and copy the following code snippet. After creating the file, use the command "node appDisabled.js" to run this code as shown in the example below −

// app.disabled() 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;

// Checking the foo property
console.log("Is Settings disabled: ", app.disabled('trust proxy'));

Output

C:\home
ode>> node appDisabled.js Is Settings disabled: true

Example 2

Let's take a look at one more example.

// app.disabled() 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;
app.enable('trust proxy');

// Checking the foo property
console.log("Is Settings disabled: ", app.disabled('trust proxy'));

Output

C:\home
ode>> node appDisabled.js Is Settings disabled: false

Updated on: 28-Mar-2022

169 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements