Registry / serialization / mime-lookup

mime-lookup

JSON →
library0.0.2jsnpmunverified

The `mime-lookup` library provides a focused utility for resolving MIME types based on file extensions. Unlike some alternatives, this package does not bundle its own MIME type database. Instead, it requires the user to supply a database, typically by integrating with the `mime-db` package. As of its only released version, 0.0.2, it offers core functionalities such as `lookup` for determining a MIME type from a given path, `extension` for retrieving a default file extension from a MIME type, and `define` for adding custom MIME type to extension mappings. It also includes `charsets.lookup` for charset mappings. Key differentiators include its lightweight nature due to the decoupled database, allowing for flexible custom database integration. First published in 2015 and last updated in 2016, the project appears to be unmaintained, making its release cadence non-existent.

npm install mime-lookup
INSTALL
IMPORT
SIG · MIME-LOOKUP
M
mime-lookup
serializationjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MimeLookup
const MimeLookup = require('mime-lookup');
import { MimeLookup } from 'mime-lookup';
This library is CommonJS-only and does not support ES module imports.
mimeDb (for database)
const mimeDb = require('mime-db');
import mimeDb from 'mime-db';
The `mime-db` package, commonly used as the database for `MimeLookup`, is also CommonJS-only.
MimeLookup (instance creation)
const mime = new MimeLookup(require('mime-db'));
const mime = new MimeLookup();
An instance of `MimeLookup` *must* be initialized with a database object; it does not come with a default.

This quickstart demonstrates how to instantiate `MimeLookup` using `mime-db`, perform basic MIME type lookups, retrieve extensions, and define custom MIME type mappings.

const MimeLookup = require('mime-lookup'); const mimeDb = require('mime-db'); // This is the recommended database // Initialize MimeLookup with the mime-db database const mime = new MimeLookup(mimeDb); console.log('--- MIME Type Lookups ---'); console.log('file.txt:', mime.lookup('file.txt')); console.log('image.jpeg:', mime.lookup('image.jpeg')); console.log('.html:', mime.lookup('.html')); console.log('unknown.xyz (default):', mime.lookup('unknown.xyz')); console.log('\n--- Extension Lookups ---'); console.log('text/html:', mime.extension('text/html')); console.log('application/json:', mime.extension('application/json')); console.log('\n--- Custom Mappings ---'); mime.define({ 'application/x-custom-format': ['xcf', 'customfmt'], 'text/markdown': ['md', 'markdown'] }); console.log('document.xcf:', mime.lookup('document.xcf')); console.log('report.md:', mime.lookup('report.md')); console.log('application/x-custom-format (extension):', mime.extension('application/x-custom-format'));
Debug
Known issues
breaking`mime-lookup` is an abandoned project, with its last commit in 2016 and no new releases since version 0.0.2. It is not actively maintained, which may lead to unaddressed bugs, security vulnerabilities, or compatibility issues with newer Node.js versions or ecosystems.
fix
Consider using alternative, actively maintained MIME type libraries such as `mime-types` or `mime` (v2+).
affects: >=0.0.2
gotchaThe `mime-lookup` library is CommonJS-only, meaning it only supports `require()` for module imports. It does not provide ES module (ESM) support.
fix
Ensure you are using CommonJS `require()` syntax for importing `mime-lookup` and any related packages like `mime-db`. For projects requiring ESM, a different library is necessary.
affects: >=0.0.2
gotcha`mime-lookup` does not include a MIME type database internally. You *must* provide one during instantiation, typically by using the `mime-db` package.
fix
Always initialize `MimeLookup` with a database, e.g., `new MimeLookup(require('mime-db'))`. Failure to do so will result in an instance that cannot resolve any MIME types.
affects: >=0.0.2
gotchaThe project's extremely low version number (0.0.2) from its initial release suggests it was either an early-stage project or intended to have a very minimal feature set. It may lack features, optimizations, or robust error handling found in more mature libraries.
fix
Thoroughly test its functionality in your specific use case. For complex or mission-critical applications, consider a more mature and actively maintained alternative.
affects: >=0.0.2
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'extensions') (or similar for 'charsets' or 'types')
The `MimeLookup` instance was created without providing a database, or the provided database object does not have the expected structure.
fix
Ensure you pass a valid MIME type database object, such as the one from `mime-db`, during instantiation: `const mime = new MimeLookup(require('mime-db'));`
Error: Cannot find module 'mime-db'
The `mime-db` package, which is commonly used to provide the MIME type database, has not been installed.
fix
Install `mime-db` as a dependency: `npm install mime-db`.
Incorrect MIME type (e.g., 'application/octet-stream') returned for a known file extension.
The provided database is either missing the entry for the specific file extension, or the `lookup` method's input path is malformed, preventing proper extension extraction.
fix
Verify that your database (e.g., `mime-db` version) contains the expected entry. Also, ensure the path passed to `mime.lookup()` is correctly formatted (e.g., `'file.ext'`, `'.ext'`). You can also `mime.define()` custom types if needed.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
mime-dboptionalProvides a comprehensive MIME type database; required for most practical uses of mime-lookup as the library itself does not bundle one.
Agent activity
2 hits · last 30 days
node
2
Resources
mime-lookup — npm install mime-lookup · libregistry