3 Support for mapping between file extensions and MIME types. This module uses the latest version of the Apache "mime.types" file (maps over 620 types to 800+ extensions). It is also trivially easy to add your own types and extensions, should you need to do that.
7 Install with [npm](http://github.com/isaacs/npm):
13 ### mime.lookup(path) - lookup the type for a file or extension
15 var mime = require('mime');
17 mime.lookup('/path/to/file.txt'); // => 'text/plain'
18 mime.lookup('file.txt'); // => 'text/plain'
19 mime.lookup('.txt'); // => 'text/plain'
20 mime.lookup('htm'); // => 'text/html'
22 ### mime.extension(type) - lookup the default extension for type
24 mime.extension('text/html'); // => 'html'
25 mime.extension('application/octet-stream'); // => 'bin'
27 ### mime.charsets.lookup() - map mime-type to charset
29 mime.charsets.lookup('text/plain'); // => 'UTF-8'
31 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
33 ## "Can you add support for [some type/extension]?"
35 Start by adding support for the type in your project using the mime.define() or mime.load() methods (documented below).
37 If there's a type that is shared across node.js modules, by different people, create an issue here and we'll add it if it makes sense.
39 If the type in question applies to projects outside the node.js community (e.g. if [IANA](http://www.iana.org/assignments/media-types/) approves a new type) file a [bug with Apache](http://httpd.apache.org/bug_report.html) and create an issue here that links to it.
41 ### mime.define() - Add custom mime/extension mappings
44 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
45 'application/x-my-type': ['x-mt', 'x-mtt'],
49 mime.lookup('x-sft'); // => 'text/x-some-format'
50 mime.extension('text/x-some-format'); // => 'x-sf'
52 ### mime.load(filepath) - Load mappings from an Apache ".types" format file
54 mime.load('./my_project.types');