node js express indicate application/json code example
Example 1: node js return json
var http = require('http');
var app = http.createServer(function(req,res){
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ a: 1 }));
});
app.listen(3000);
// > {"a":1}
Example 2: http header express
app.get('/', (req, res) => {
req.header('User-Agent')
})
// Use the Request.header() method to access
//one individual request header’s value