Tuesday 26 February 2019

Express: app.get(name): Return the value associated with this property


app.get(name)
Returns the value of name app setting

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