Search code examples
javascriptnode.jshttp-headersexpressoffline-caching

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


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


Solution

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