Why isn't express-js setting the Content-Type header?

Kit Sunde picture Kit Sunde · Mar 23, 2011 · Viewed 64.4k times · Source

I have the following:

var express = require('express'),
    app = express.createServer();

app.get("/offline.manifest", function(req, res){
  res.contentType("text/cache-manifest");
  res.end("CACHE MANIFEST");
});

app.listen(8561);

The network tab in Chrome says it's text/plain. Why isn't it setting the header?

The code above works, my problems were caused by a linking to an old version of express-js

Answer

Ray Hulha picture Ray Hulha · Oct 23, 2016

res.type('json') works too now and as others have said, you can simply use
res.json({your: 'object'})