App Enabled Method in Express.js



The app.enabled() method checks whether a setting name property is enabled or not. It basically checks the value of a setting name and returns True if the property value is also True.

Syntax

app.enabled( name )

Example 1

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

// app.enabled() 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("Trust proxy settings are set to: ",
app.enabled('trust proxy'));

Output

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

Example 2

Let's take a look at one more example.

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

// Enabling 'trust proxy' settings
app.enable('trust proxy');

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

Output

C:\home
ode >> node appEnabled.js Trust proxy settings are set to: true
Updated on: 2022-01-29T07:11:22+05:30

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements