{"id":16439,"library":"mime-names","title":"MIME Type Names Database","description":"mime-names is a JavaScript package that provides a database of human-readable names and common file extensions, keyed by MIME types. It is designed to complement `mime-db`, offering a more descriptive layer on top of MIME type definitions. This package does not aim to be an exhaustive list of all MIME types, focusing instead on popular and commonly used formats. Developers should anticipate that some less common MIME types might not be present and implement graceful handling for such cases. The current stable version is 1.0.0, and releases are typically made as needed to add new types or update existing data. Its primary differentiator is its direct, lookup-table structure and its specific focus on human-readable names and extensions rather than broader MIME type resolution logic.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/tommoor/mime-names","tags":["javascript","mime","db","names","type","types","database"],"install":[{"cmd":"npm install mime-names","lang":"bash","label":"npm"},{"cmd":"yarn add mime-names","lang":"bash","label":"yarn"},{"cmd":"pnpm add mime-names","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports the entire database object as its default export. There are no named exports. Node.js's ESM interop for CommonJS allows this default import pattern.","wrong":"import { db } from 'mime-names';","symbol":"db","correct":"import db from 'mime-names';"},{"note":"This package is primarily a CommonJS module, and this is the direct and intended way to access the database object in CommonJS environments.","symbol":"db (CommonJS)","correct":"const db = require('mime-names');"}],"quickstart":{"code":"import db from 'mime-names';\n\nconst mimeType = 'application/json';\nconst data = db[mimeType];\n\nif (data) {\n  console.log(`MIME Type: ${mimeType}`);\n  console.log(`  Name: ${data.name}`);\n  console.log(`  Extensions: ${data.extensions ? data.extensions.join(', ') : 'None'}`);\n} else {\n  console.log(`No data found for MIME type: ${mimeType}`);\n}\n\nconst unknownMimeType = 'application/x-custom-type';\nconst unknownData = db[unknownMimeType];\nif (!unknownData) {\n  console.log(`\\nAs expected, no data for ${unknownMimeType} (not all-encompassing).`);\n}\n","lang":"javascript","description":"Demonstrates how to import the MIME database and look up information for a specific MIME type, including handling cases where a type might not be found. It illustrates accessing the name and extensions properties."},"warnings":[{"fix":"Always check if the lookup result is `undefined` before trying to access its properties. E.g., `const data = db[mimeType]; if (data) { /* use data */ }`","message":"The `mime-names` database is not comprehensive and explicitly states it 'does not try to be all encompassing'. It focuses on popular file formats. Your application code must gracefully handle cases where a MIME type might not exist in this database.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid directly adding, deleting, or modifying properties on the `db` object. If custom MIME type data is needed, merge it into a separate, application-specific object.","message":"The `db` object returned by `mime-names` should be treated as read-only. While JavaScript allows mutation of objects, modifying this imported database can lead to unexpected behavior or inconsistencies, especially if parts of your application rely on its original state.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure that the MIME type entry is not `undefined` before accessing its properties. `const data = db[mimeType]; if (data) { console.log(data.name); }`","cause":"Attempting to access properties like `.name` or `.extensions` on a MIME type that does not exist in the `mime-names` database without first checking if the entry exists.","error":"TypeError: Cannot read properties of undefined (reading 'name')"},{"fix":"Use a default import to get the entire database object: `import db from 'mime-names';`. The package does not offer individual named exports for specific MIME types or utility functions.","cause":"Incorrectly attempting to use named imports (e.g., `import { SomeExport } from 'mime-names'`) when the package only provides a default export (the entire database object).","error":"SyntaxError: The requested module 'mime-names' does not provide an export named 'SomeExport'"}],"ecosystem":"npm"}