{"id":11326,"library":"mime-lookup","title":"MIME Type Lookup Utility","description":"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.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/Hypercubed/mime-lookup","tags":["javascript","util","mime"],"install":[{"cmd":"npm install mime-lookup","lang":"bash","label":"npm"},{"cmd":"yarn add mime-lookup","lang":"bash","label":"yarn"},{"cmd":"pnpm add mime-lookup","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides a comprehensive MIME type database; required for most practical uses of mime-lookup as the library itself does not bundle one.","package":"mime-db","optional":true}],"imports":[{"note":"This library is CommonJS-only and does not support ES module imports.","wrong":"import { MimeLookup } from 'mime-lookup';","symbol":"MimeLookup","correct":"const MimeLookup = require('mime-lookup');"},{"note":"The `mime-db` package, commonly used as the database for `MimeLookup`, is also CommonJS-only.","wrong":"import mimeDb from 'mime-db';","symbol":"mimeDb (for database)","correct":"const mimeDb = require('mime-db');"},{"note":"An instance of `MimeLookup` *must* be initialized with a database object; it does not come with a default.","wrong":"const mime = new MimeLookup();","symbol":"MimeLookup (instance creation)","correct":"const mime = new MimeLookup(require('mime-db'));"}],"quickstart":{"code":"const MimeLookup = require('mime-lookup');\nconst mimeDb = require('mime-db'); // This is the recommended database\n\n// Initialize MimeLookup with the mime-db database\nconst mime = new MimeLookup(mimeDb);\n\nconsole.log('--- MIME Type Lookups ---');\nconsole.log('file.txt:', mime.lookup('file.txt'));\nconsole.log('image.jpeg:', mime.lookup('image.jpeg'));\nconsole.log('.html:', mime.lookup('.html'));\nconsole.log('unknown.xyz (default):', mime.lookup('unknown.xyz'));\n\nconsole.log('\\n--- Extension Lookups ---');\nconsole.log('text/html:', mime.extension('text/html'));\nconsole.log('application/json:', mime.extension('application/json'));\n\nconsole.log('\\n--- Custom Mappings ---');\nmime.define({\n    'application/x-custom-format': ['xcf', 'customfmt'],\n    'text/markdown': ['md', 'markdown']\n});\nconsole.log('document.xcf:', mime.lookup('document.xcf'));\nconsole.log('report.md:', mime.lookup('report.md'));\nconsole.log('application/x-custom-format (extension):', mime.extension('application/x-custom-format'));","lang":"javascript","description":"This quickstart demonstrates how to instantiate `MimeLookup` using `mime-db`, perform basic MIME type lookups, retrieve extensions, and define custom MIME type mappings."},"warnings":[{"fix":"Consider using alternative, actively maintained MIME type libraries such as `mime-types` or `mime` (v2+).","message":"`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.","severity":"breaking","affected_versions":">=0.0.2"},{"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.","message":"The `mime-lookup` library is CommonJS-only, meaning it only supports `require()` for module imports. It does not provide ES module (ESM) support.","severity":"gotcha","affected_versions":">=0.0.2"},{"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.","message":"`mime-lookup` does not include a MIME type database internally. You *must* provide one during instantiation, typically by using the `mime-db` package.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Thoroughly test its functionality in your specific use case. For complex or mission-critical applications, consider a more mature and actively maintained alternative.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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'));`","cause":"The `MimeLookup` instance was created without providing a database, or the provided database object does not have the expected structure.","error":"TypeError: Cannot read properties of undefined (reading 'extensions') (or similar for 'charsets' or 'types')"},{"fix":"Install `mime-db` as a dependency: `npm install mime-db`.","cause":"The `mime-db` package, which is commonly used to provide the MIME type database, has not been installed.","error":"Error: Cannot find module 'mime-db'"},{"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.","cause":"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.","error":"Incorrect MIME type (e.g., 'application/octet-stream') returned for a known file extension."}],"ecosystem":"npm"}