{"id":16124,"library":"mime-db","title":"MIME Database","description":"mime-db is a comprehensive, machine-readable database of media types and associated metadata. It aggregates data from official sources such as IANA, Apache, and nginx, providing detailed information including common file extensions, compressibility, and default charsets for thousands of MIME types. The current stable version is 1.54.0. The package maintains a frequent release cadence, primarily driven by updates to its upstream data sources and community contributions for custom types. A key differentiator is its minimalist approach: it is distributed as a pure JSON data file with no accompanying logic or API, making it lightweight and un-opinionated. This design ensures maximum flexibility, although consumers must implement their own lookup logic. Crucially, changes to the underlying MIME type data are *not* considered breaking changes under its semver policy for the programmatic API, meaning data can change between minor or patch versions.","status":"active","version":"1.54.0","language":"javascript","source_language":"en","source_url":"https://github.com/jshttp/mime-db","tags":["javascript","mime","db","type","types","database","charset","charsets"],"install":[{"cmd":"npm install mime-db","lang":"bash","label":"npm"},{"cmd":"yarn add mime-db","lang":"bash","label":"yarn"},{"cmd":"pnpm add mime-db","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single default object containing the MIME database.","wrong":"import { db } from 'mime-db';","symbol":"db","correct":"import db from 'mime-db';"},{"note":"CommonJS import for Node.js environments. The package is effectively a JSON object.","symbol":"db","correct":"const db = require('mime-db');"},{"note":"For browser usage, directly fetching the JSON file from a CDN is common. It's crucial to pin a specific version tag for stability, as the master branch's format or content can change without semver guarantees.","wrong":"fetch('https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json').then(res => res.json());","symbol":"direct CDN access","correct":"fetch('https://cdn.jsdelivr.net/gh/jshttp/mime-db@1.54.0/db.json').then(res => res.json());"}],"quickstart":{"code":"import db from 'mime-db';\n\ninterface MimeEntry {\n  source?: 'apache' | 'iana' | 'nginx';\n  extensions?: string[];\n  compressible?: boolean;\n  charset?: string;\n}\n\n// Access the entire database\nconsole.log(`Total MIME types in database: ${Object.keys(db).length}`);\n\n// Get data for a specific MIME type\nconst javascriptData: MimeEntry = db['application/javascript'];\nif (javascriptData) {\n  console.log(`\nInformation for application/javascript:\n  Source: ${javascriptData.source ?? 'custom'}\n  Extensions: ${javascriptData.extensions?.join(', ') ?? 'N/A'}\n  Compressible: ${javascriptData.compressible ? 'Yes' : 'No'}\n  Charset: ${javascriptData.charset ?? 'N/A'}\n`);\n}\n\n// Find MIME types by extension (example logic, not built-in)\nconst findMimeTypeByExtension = (ext: string): string[] => {\n  const matchingTypes: string[] = [];\n  for (const mimeType in db) {\n    if (db[mimeType].extensions?.includes(ext.toLowerCase())) {\n      matchingTypes.push(mimeType);\n    }\n  }\n  return matchingTypes;\n};\n\nconst htmlMimeTypes = findMimeTypeByExtension('html');\nconsole.log(`MIME types associated with '.html': ${htmlMimeTypes.join(', ')}`);","lang":"typescript","description":"Demonstrates importing the mime-db and accessing information for specific MIME types. It also includes example logic for reverse lookup by extension, showing common usage patterns."},"warnings":[{"fix":"If your application relies on specific, stable MIME type data, you must pin your `mime-db` dependency to an exact version (e.g., `\"mime-db\": \"1.54.0\"`) rather than using a caret (`^`) or tilde (`~`) range. Alternatively, implement robust error handling or data validation in your application to account for potential data evolution.","message":"The `mime-db` package's semver policy explicitly states that changes to the underlying MIME type data are NOT considered breaking changes for the programmatic API. This means that MIME type definitions (e.g., extensions, compressibility) can change in minor or patch releases, potentially affecting data-dependent logic without a major version bump.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always specify a particular release tag in your CDN URL to ensure stability and compatibility, for example, `https://cdn.jsdelivr.net/gh/jshttp/mime-db@1.54.0/db.json`.","message":"When consuming `db.json` directly from a CDN (e.g., via jsDelivr), using the `master` branch URL (`.../master/db.json`) is highly discouraged. The format or content of the JSON file on the `master` branch can change at any time, leading to unexpected issues in production.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For highly sensitive applications, consider augmenting `mime-db` data with additional custom checks or more specialized MIME type libraries that provide stronger validation or inference logic.","message":"The database contains entries from various sources (IANA, Apache, nginx) and custom types. While efforts are made to keep it updated, there might be discrepancies or omissions, especially for less common or newly emerging media types. Relying solely on `mime-db` for critical security or validation purposes without further checks may be insufficient.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Always check if the returned entry for a MIME type is defined before attempting to access its properties, e.g., `const data = db['unknown/type']; if (data) { /* use data */ }`.","cause":"Attempting to access properties of a MIME type entry that does not exist in the database, often due to a typo in the MIME type string or querying for an unsupported type.","error":"TypeError: Cannot read properties of undefined (reading 'extensions')"},{"fix":"Pin your `mime-db` dependency to an exact version in your `package.json` (e.g., `\"mime-db\": \"1.54.0\"`) to prevent unexpected data changes. Regularly review release notes for data changes and update the pinned version proactively when desired.","cause":"This is a direct consequence of the package's semver policy where changes to the MIME type data itself are not considered breaking API changes. New extensions, removed extensions, or changes in compressibility flags can occur in non-major versions.","error":"My application's file type detection logic broke after a 'patch' or 'minor' update of mime-db."}],"ecosystem":"npm"}