Why doesn't express-js set 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 is text/plain . Why doesn't he set a title?

The code above, my problems were caused by a link to the old version of express-js

+16
source share
3 answers

res.type('json') is also working now, and as others have said, you can just use res.json({your: 'object'})

+23
source

Try this code:

 var express = require('express'), app = express.createServer(); app.get("/offline.manifest", function(req, res){ res.header("Content-Type", "text/cache-manifest"); res.end("CACHE MANIFEST"); }); app.listen(8561); 

(I assume you are using the latest version of express, 2.0.0)

UPDATE: I just quickly tested using Firefox 3.6.x and Live HTTP Headers. This is the output of the addons:

  HTTP/1.1 200 OK X-Powered-By: Express Content-Type: text/cache-manifest Connection: keep-alive Transfer-Encoding: chunked 

Before you try, make sure you clear the cache.

+17
source

instead of res.send()

use res.json() , which automatically sets the application/json content type

+1
source

All Articles