I know Express has the res.contentType() method, but how to set automatically content type based on path/file (including static content)?
Run the following cmd :
npm install xmimetype ;
Then , in your code :
var xm=require("xmimetype");
xm.mimetypeOf("java");
xm.mimetypeOf("./lib/Person.java");
// -> text/x-java-source
xm.mimetypeOf("docx");
xm.mimetypeOf("./lib/overview.docx");
// -> application/vnd.openxmlformats-officedocument.wordprocessingml.document
For more info , check GIT repository .
The opposite is available :
xm.extensionsOf("image/jpeg");
// -> [ 'jpeg', 'jpg', 'jpe' ]