Tuesday 26 February 2019

Express: app.set(name, value): Set application property


app.set(name, value)
This method is used to set application properties.

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

You can get the application properties using get method.

version = app.get('version')
maintenanceSupported = app.get('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.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’, you can see application specific properties.




Previous                                                 Next                                                 Home

No comments:

Post a Comment