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-lookupVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `MimeLookup` using `mime-db`, perform basic MIME type lookups, retrieve extensions, and define custom MIME type mappings.
Consider using alternative, actively maintained MIME type libraries such as `mime-types` or `mime` (v2+).
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.
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.Thoroughly test its functionality in your specific use case. For complex or mission-critical applications, consider a more mature and actively maintained alternative.
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'));`Install `mime-db` as a dependency: `npm install mime-db`.
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.