Express: Setting content-type based on path/file?

mahemoff picture mahemoff · Aug 18, 2011 · Viewed 46.3k times · Source

I know Express has the res.contentType() method, but how to set automatically content type based on path/file (including static content)?

Answer

Andrei Neculau picture Andrei Neculau · Jul 5, 2012

Also, if you want to extend the mime-types that express(connect) knows about, you can do

express.static.mime.define({'text/plain': ['md']});

or

connect.static.mime.define({'text/plain': ['md']});

PS: the mime module is now located at https://github.com/broofa/node-mime