3 Comprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.
7 Install with [npm](http://github.com/isaacs/npm):
14 Get the mime type associated with a file. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
16 var mime = require('mime');
18 mime.lookup('/path/to/file.txt'); // => 'text/plain'
19 mime.lookup('file.txt'); // => 'text/plain'
20 mime.lookup('.TXT'); // => 'text/plain'
21 mime.lookup('htm'); // => 'text/html'
23 ### mime.extension(type)
24 Get the default extension for `type`
26 mime.extension('text/html'); // => 'html'
27 mime.extension('application/octet-stream'); // => 'bin'
29 ### mime.charsets.lookup()
31 Map mime-type to charset
33 mime.charsets.lookup('text/plain'); // => 'UTF-8'
35 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
37 ## API - Defining Custom Types
39 The following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).
43 Add custom mime/extension mappings
46 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
47 'application/x-my-type': ['x-mt', 'x-mtt'],
51 mime.lookup('x-sft'); // => 'text/x-some-format'
53 The first entry in the extensions array is returned by `mime.extension()`. E.g.
55 mime.extension('text/x-some-format'); // => 'x-sf'
57 ### mime.load(filepath)
59 Load mappings from an Apache ".types" format file
61 mime.load('./my_project.types');
63 The .types file format is simple - See the `types` dir for examples.