Know what
you’re sending.
A small, reviewed vocabulary of MIME constants and practical helpers for headers, uploads, URLs, and file extensions.
Filename lookup · no byte inspection
Install / package manager
One package.
Use your tool.
Type declarations ship with the package. There is nothing else to configure.
npm install mime-types-liteThe useful middle
More than constants.
Less than a database.
Resolve a filename, clean a real Content-Type header, or test a category wildcard with functions that compose.
Find a type from a path
Accepts extensions, filenames, Windows paths, and URLs with query strings.
fromExtension('reports/annual.pdf')
// 'application/pdf'
fromExtension('PHOTO.JPEG')
// 'image/jpeg'from-extension Normalize headers
Remove parameters, trim whitespace, lowercase, and validate.
normalizeMimeType(
' Application/JSON; charset=utf-8 '
)
// 'application/json'normalize Match the category
Test exact media types, category wildcards, or the universal wildcard.
matchesMimeType(
'image/avif',
'image/*'
)
// truematching Standards first
The modern answer,
with the old one nearby.
Current standards are the defaults. Historical values remain in LEGACY_MIME when interoperability requires them.
text/javascriptapplication/yamlimage/vnd.microsoft.iconA useful boundary
A MIME type is a label, not proof.
Extensions and Content-Type headers can be attacker-controlled. Inspect signatures and enforce limits for untrusted uploads.
Security notes →