Saturday 16 March 2019

Express: res.get(field): Get http response header field


res.get(field)
Return http response header value associated with this field.

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.set({
   'Content-Type': 'text/plain',
   'name' : 'demo on response headers'
 })
 
 var contentType = res.get('Content-Type')
 var name = res.get('name')
 
 console.log(`contentType : ${contentType}`)
 console.log(`name : ${name}`)
 
 res.send('Hello World')

})

const port = 3000
app.listen(port, () => console.log(`Application started listening on port ${port}!`))

Run index.js


Open the url ‘http://localhost:3000/’ in browser.



Previous                                                 Next                                                 Home

No comments:

Post a Comment