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, if no mime type is found `application/octet-stream` is returned. 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'
24 Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
26 ### mime.extension(type)
27 Get the default extension for `type`
29 mime.extension('text/html'); // => 'html'
30 mime.extension('application/octet-stream'); // => 'bin'
32 ### mime.charsets.lookup()
34 Map mime-type to charset
36 mime.charsets.lookup('text/plain'); // => 'UTF-8'
38 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
40 ## API - Defining Custom Types
42 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).
46 Add custom mime/extension mappings
49 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
50 'application/x-my-type': ['x-mt', 'x-mtt'],
54 mime.lookup('x-sft'); // => 'text/x-some-format'
56 The first entry in the extensions array is returned by `mime.extension()`. E.g.
58 mime.extension('text/x-some-format'); // => 'x-sf'
60 ### mime.load(filepath)
62 Load mappings from an Apache ".types" format file
64 mime.load('./my_project.types');
66 The .types file format is simple - See the `types` dir for examples.