Friday 8 March 2019

Express: req.get(field): Access http request headers


req.get(field)
This method returns the value of the header field.

Example
req.get('Content-Type');

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 var acceptContentType = req.get('Accept')
 
 var result = `acceptContentType : ${acceptContentType}`
 
 res.send(result)
 
})

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


Previous                                                 Next                                                 Home

No comments:

Post a Comment