Tuesday 26 February 2019

Express: app.enable(name): Enable the property


app.enable(name)
Sets the Boolean setting name to true

Example
app.enable('maintenanceSupported')

index.js
var express = require('express')

var app = express()

app.set('version', '1.2.31')
app.set('maintenanceSupported', true)

function getAppInfo(){
 version = app.get('version')
 maintenanceSupported = !app.disabled('maintenanceSupported')
 return `maintenanceSupported : ${maintenanceSupported}, <br />version : ${version}`
}

app.get('/', (req, res) => {
 res.send("Hello World")
})

app.get('/appInfo', (req, res) => {
 res.send(getAppInfo())
})

app.get('/disableMaintenance', (req, res) => {
 app.disable('maintenanceSupported')
 res.send(getAppInfo())
})

app.get('/enableMaintenance', (req, res) => {
 app.enable('maintenanceSupported')
 res.send(getAppInfo())
})


app.listen(3000, () => {console.log("Application started in port 3000")});

Run index.js.


Open the url ‘localhost:3000/appInfo’.


Open the url ‘http://localhost:3000/disableMaintenance’ to stop maintenance.

Open the url ‘http://localhost:3000/enableMaintenance’, to enable maintenance.


Previous                                                 Next                                                 Home

No comments:

Post a Comment