3 Comprehensive MIME type mapping API based on mime-db module.
7 Install with [npm](http://github.com/isaacs/npm):
11 ## Contributing / Testing
21 > mime scripts/jquery.js
22 application/javascript
27 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.
30 var mime = require('mime');
32 mime.lookup('/path/to/file.txt'); // => 'text/plain'
33 mime.lookup('file.txt'); // => 'text/plain'
34 mime.lookup('.TXT'); // => 'text/plain'
35 mime.lookup('htm'); // => 'text/html'
39 Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
41 ### mime.extension(type)
42 Get the default extension for `type`
45 mime.extension('text/html'); // => 'html'
46 mime.extension('application/octet-stream'); // => 'bin'
49 ### mime.charsets.lookup()
51 Map mime-type to charset
54 mime.charsets.lookup('text/plain'); // => 'UTF-8'
57 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
59 ## API - Defining Custom Types
61 Custom type mappings can be added on a per-project basis via the following APIs.
65 Add custom mime/extension mappings
69 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
70 'application/x-my-type': ['x-mt', 'x-mtt'],
74 mime.lookup('x-sft'); // => 'text/x-some-format'
77 The first entry in the extensions array is returned by `mime.extension()`. E.g.
80 mime.extension('text/x-some-format'); // => 'x-sf'
83 ### mime.load(filepath)
85 Load mappings from an Apache ".types" format file
88 mime.load('./my_project.types');
90 The .types file format is simple - See the `types` dir for examples.