Nodejs how to set content-type header for every request
To update the request headers please add below custom middleware before bodyparser
app.use(function (req, res, next) {
req.headers['content-type'] = 'application/json';
next();
});
If still not working check the case of 'content-type' sent by your client. Put the 'content-type' in the same case
Response object has to use .setHeader
instead of .header
:
app.use(function(req, res, next) {
res.setHeader("Content-Type", "application/json");
next();
});
doc.