mime
Lightweight MIME type detection library for Node.js and browsers. Maps file extensions to MIME types (e.g., '.js' → 'text/javascript', '.png' → 'image/png') and vice versa. Implements the MIME Database (mime-db) with comprehensive type coverage. Two variants: mime (full database, larger) and mime/lite (smaller subset). The standard library for Content-Type header determination when serving files or handling uploads in Node.js HTTP servers.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Extension-based MIME detection only — not a security tool. Do not rely on MIME type for security decisions without content-based validation.
⚡ Reliability
Best When
You need quick, reliable MIME type lookup by file extension for Content-Type headers in Node.js HTTP servers or file handling code.
Avoid When
You need to detect MIME type from file content (magic bytes) rather than extension — use the file-type library for content-based detection.
Use Cases
- • Determine Content-Type headers when serving static files from a Node.js server based on file extension
- • Validate that uploaded file extensions match their claimed MIME type for file upload security
- • Look up file extensions for a MIME type when generating downloadable content with correct browser handling
- • Classify uploaded files by type (image, video, document) for storage organization or processing routing
- • Generate appropriate Content-Disposition headers for file downloads by detecting MIME type from filename
Not For
- • Magic number MIME detection from file content — mime uses extension-based detection only; use file-type for content-based detection
- • Complete MIME type validation for security — extension-to-MIME mapping can be spoofed; use file-type for genuine content validation
- • Very large file type databases — mime-db is comprehensive but use specialized libraries for exotic formats
Interface
Authentication
No authentication — lookup utility library.
Pricing
Fully free, MIT licensed.
Agent Metadata
Known Gotchas
- ⚠ mime v4 is ESM-only — use mime v3 for CommonJS or the mime-types package (which is CJS-compatible)
- ⚠ Unknown extensions return undefined — always null-check and provide a fallback: mime.getType('.xyz') ?? 'application/octet-stream'
- ⚠ MIME type lookup is extension-based not content-based — attackers can rename a .exe to .jpg; use file-type for security-sensitive upload validation
- ⚠ mime and mime-types are different packages — mime-types includes .lookup() and .contentType() with charset support; choose based on your needs
- ⚠ Custom MIME types can be defined with mime.define() — but these are per-instance and must be re-registered on each import
- ⚠ Not all MIME types have standard extensions — mime.getExtension('application/json') returns 'json', but some MIME types have no registered extension
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for mime.
Scores are editorial opinions as of 2026-03-06.