![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Express.js – app.enable() Method
The app.enable() function sets the Boolean setting ‘name’ to ‘true’, where name defines one of the properties from the app settings table. Using the app.set('foo', true) for a Boolean property is same as calling the app.enable('foo') function.
Syntax
app.enable(name)
Example 1
Create a file with the name "appEnable.js" and copy the following code snippet. After creating the file, use the command "node appEnable.js" to run this code.
// app.enable() 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') console.log(app.get('trust proxy')); // App listening on the below port app.listen(PORT, function(err){ if (err) console.log(err); console.log("Server listening on PORT", PORT); });
Output
C:\home
ode>> node appEnable.js true Server listening on PORT 3000
Example 2
Let’s take a look at one more example.
// app.enable() 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('foo') console.log("Is foo enabled --", app.get('foo'));
Output
C:\home
ode>> node appEnable.js Is foo enabled – true
Advertisements