simple-mime
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript
A minimal mime type lookup library for Node.js, providing a simple function to map file extensions to MIME types. Version 0.1.0 is the current stable release. It focuses on being lightweight and dependency-free, unlike the more feature-rich `mime` package. Ideal for small static file servers where minimalism is preferred.
Common errors
error TypeError: object is not a function ↓
cause Requiring the module without calling it returns a function, not a lookup function.
fix
Change require('simple-mime') to require('simple-mime')('application/octet-stream')
Warnings
gotcha The module must be called immediately to create the lookup function; otherwise you get a function instead of a value. ↓
fix Always call require('simple-mime')('your-fallback') to get the proper lookup function.
gotcha The fallback MIME type is required; passing no argument will result in undefined being used as fallback. ↓
fix Always provide a fallback string like 'application/octet-stream'.
deprecated The package uses deprecated Node.js APIs (e.g., path.exists) which may cause deprecation warnings in newer Node.js versions. ↓
fix Consider switching to the more maintained 'mime' package or updating the dependency.
Install
npm install simple-mime yarn add simple-mime pnpm add simple-mime Imports
- default wrong
const mime = require('simple-mime')correctvar getMimeType = require('simple-mime')('application/octet-stream') - lookup function wrong
var type = getMimeType['mp3']correctvar type = getMimeType('file.mp3') - default export (ESM) wrong
import { getMimeType } from 'simple-mime'correctimport createMime from 'simple-mime'; const getMimeType = createMime('application/octet-stream')
Quickstart
var getMimeType = require('simple-mime')('text/plain');
console.log(getMimeType('file.html')); // 'text/html'
console.log(getMimeType('file.js')); // 'application/javascript'
console.log(getMimeType('file.xyz')); // 'text/plain' (fallback)