Registry / data / mime-db

mime-db

JSON →
library1.54.0jsnpmunverified

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.

npm install mime-db
INSTALL
IMPORT
SIG · MIME-DB
M
mime-db
datajavascriptv1.54.0
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.

db
import db from 'mime-db';
import { db } from 'mime-db';
The package exports a single default object containing the MIME database.
db
const db = require('mime-db');
CommonJS import for Node.js environments. The package is effectively a JSON object.
direct CDN access
fetch('https://cdn.jsdelivr.net/gh/jshttp/mime-db@1.54.0/db.json').then(res => res.json());
fetch('https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json').then(res => res.json());
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.

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.

import db from 'mime-db'; interface MimeEntry { source?: 'apache' | 'iana' | 'nginx'; extensions?: string[]; compressible?: boolean; charset?: string; } // Access the entire database console.log(`Total MIME types in database: ${Object.keys(db).length}`); // Get data for a specific MIME type const javascriptData: MimeEntry = db['application/javascript']; if (javascriptData) { console.log(` Information for application/javascript: Source: ${javascriptData.source ?? 'custom'} Extensions: ${javascriptData.extensions?.join(', ') ?? 'N/A'} Compressible: ${javascriptData.compressible ? 'Yes' : 'No'} Charset: ${javascriptData.charset ?? 'N/A'} `); } // Find MIME types by extension (example logic, not built-in) const findMimeTypeByExtension = (ext: string): string[] => { const matchingTypes: string[] = []; for (const mimeType in db) { if (db[mimeType].extensions?.includes(ext.toLowerCase())) { matchingTypes.push(mimeType); } } return matchingTypes; }; const htmlMimeTypes = findMimeTypeByExtension('html'); console.log(`MIME types associated with '.html': ${htmlMimeTypes.join(', ')}`);
Debug
Known issues
gotchaThe `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.
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.
affects: >=1.0.0
gotchaWhen 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.
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`.
affects: >=1.0.0
gotchaThe 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'extensions')
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.
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 */ }`.
My application's file type detection logic broke after a 'patch' or 'minor' update of mime-db.
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.
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.
Upgrade
Version history
1.54.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
mime-db — npm install mime-db · libregistry