mime-types
Comprehensive MIME type lookup library for Node.js. Maps file extensions to MIME types (lookup) and MIME types to extensions (extension). Used in web servers, file upload handlers, and HTTP agents to set correct Content-Type headers and validate file extensions. Minimal, no-dependency library based on the mime-db database of 1000+ types.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Zero dependencies. Read-only lookup — no side effects. Extension-based MIME detection should be combined with file-type content detection for security-critical file validation.
⚡ Reliability
Best When
You need fast, zero-dependency extension-to-MIME mapping in Node.js HTTP handlers or file processing pipelines.
Avoid When
You need to detect file type from binary content (use file-type) or register custom MIME types (use mime npm package).
Use Cases
- • Set correct Content-Type headers when serving files in agent HTTP servers — lookup('.pdf') returns 'application/pdf'
- • Validate uploaded file extensions against expected MIME types in agent file upload processing
- • Determine file extension from Content-Type response headers in agent HTTP clients downloading files from APIs
- • Generate correct Accept headers in agent HTTP requests when fetching specific file types from external APIs
- • Build file routing logic in agent pipelines based on MIME type — route images, PDFs, and CSVs to different processors
Not For
- • Detecting actual file type from binary content — use file-type for magic byte detection; mime-types only does extension-to-MIME mapping
- • Custom/proprietary MIME types — mime-types uses a fixed database; use the mime package for custom type registration
- • Browser environments — browsers have native MIME type handling; mime-types is for Node.js server-side use
Interface
Authentication
No authentication — local lookup table library.
Pricing
mime-types is open source and free.
Agent Metadata
Known Gotchas
- ⚠ mime.lookup() returns false for unknown extensions (not null, not undefined) — check if (mimeType) before using; comparison with false is required
- ⚠ mime.contentType('.html') returns 'text/html; charset=utf-8' with charset — strip charset for raw MIME type comparisons using .split(';')[0]
- ⚠ mime.extension() returns the most common extension for a MIME type — 'image/jpeg' returns 'jpeg' not 'jpg'; normalize if specific extension is required
- ⚠ mime-types doesn't support custom type registration — use the mime package (mime.define()) if you need to add proprietary MIME types
- ⚠ Some multi-extension types return different results — 'application/x-www-form-urlencoded' has no extension; always check for false return value
- ⚠ MIME database updates require package updates — new file formats won't be recognized until mime-db is updated; check mime-db version for coverage
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for mime-types.
Scores are editorial opinions as of 2026-03-06.