Tuesday, 26 February 2019

Express: app.disabled(name): Return true if this property is disabled


app.disabled(name)
Returns true if the Boolean setting name is disabled.

Example
maintenanceSupported = app.disabled('maintenanceSupported')

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

var app = express()

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

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

app.get('/appinfo', (req, res) => {
 version = app.get('version')
 maintenanceSupported = !app.disabled('maintenanceSupported')
 
 res.send(`maintenanceSupported : ${maintenanceSupported}, <br />version : ${version}`)
})

app.get('/disableMaintenance', (req, res) => {
 app.disable('maintenanceSupported')
 version = app.get('version')
 maintenanceSupported = app.get('maintenanceSupported')
 
 res.send(`maintenanceSupported : ${maintenanceSupported}, <br />version : ${version}`)
})


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


Run index.js and hit the url ‘http://localhost:3000/appInfo’.

Hit the url ‘http://localhost:3000/disableMaintenance’.



hit the url ‘http://localhost:3000/appInfo’ again.




Previous                                                 Next                                                 Home

No comments:

Post a Comment