API Reference

mime-types

Utility to look up MIME types from file extensions and extensions from MIME types, with charset defaults.

Official Documentation ↗
CompatibilityThis documentation covers version v3.0.2. Check the official docs for the latest API surface.

Installation

npmnpm install mime-types

Methods

mime-types maps extensions to content types and back using the mime-db dataset.

Key Features

  • Extension to MIME type lookup
  • MIME type back to extension
  • Content-Type with charset defaults

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T17:49:40+08:00 via WebFetch https://raw.githubusercontent.com/jshttp/mime-types/master/README.md.

FAQ

What does a false return mean?
false indicates no mapping exists for the input, so callers should fall back to application/octet-stream instead of assuming a type.
Where does the data come from?
The mime-db dataset, which aggregates IANA registrations and common community mappings.
Does it detect encoding by content?
No. It maps names and types only. Use a content sniffing library when you must detect the type from bytes.