mime

Comprehensive, dependency-free MIME type detection and file extension mapping for JavaScript and TypeScript.

Library
npm
v4.1.1
2,359 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
65 /100 Good
Development Activity 60
Maintenance 36
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 75
Code Quality 85
Innovation 55
Learning Curve 90

mime is a dependency-free JavaScript library that maps file extensions to MIME types and back, covering the full mime-db type registry (800+ types, 1,000+ extensions) plus additional IANA-registered types not present in mime-db. It ships built-in TypeScript definitions, so consumers no longer need a separate @types/mime package, and targets modern ES2020+ runtimes with native ESM support.

Beyond the default frozen mime singleton, the library exposes a Mime class for building custom, mutable type maps — useful for registering proprietary extensions or excluding types you don’t need. A companion mime/lite export trims out the long tail of unofficial x-*, vnd.*, and prs.* types for smaller bundles, and a bundled CLI (mime <file> / mime -r <type>) exposes the same lookups from the command line.

What You Get

  • Full mime-db type coverage (800+ MIME types, 1,000+ extensions) via mime.getType() and mime.getExtension()
  • A mime/lite variant stripped of unofficial x-*/vnd.*/prs.* types for smaller bundles
  • Built-in TypeScript declarations — no separate @types/mime package needed
  • A custom Mime class constructor for building your own mutable type maps with define()
  • A zero-dependency, tree-shakeable ESM build with a small footprint
  • A bundled mime CLI for extension/type lookups from the shell

Common Use Cases

  • Setting the correct Content-Type header when serving static files or file uploads
  • Validating uploaded file extensions against expected MIME types
  • Inferring file type from an uploaded filename in a Node.js or edge API handler
  • Mapping MIME types back to a default extension when writing downloaded files

Under The Hood

Architecture

The library is a small, single-purpose module built around one core abstraction: src/Mime.ts defines a Mime class holding three private maps (extensionToType, typeToExtension, typeToExtensions) populated by a define() method. src/index.ts composes the public default export by instantiating Mime with the generated types/standard.ts and types/other.ts tables and freezing the result via _freeze() so consumers can’t mutate the shared singleton; src/index_lite.ts builds the same way but omits the other (non-standard) table for a smaller footprint. src/mime_cli.ts is a thin wrapper around the same getType/getExtension calls, exposed as a binary through bin/cli.js. There are no layers, no dependency injection, and no external data fetching at runtime — everything a consumer calls resolves against the in-memory maps built once at import time, so any change to the Mime class’s internal map structure would ripple through getType, getExtension, getAllExtensions, and the CLI simultaneously.

Tech Stack

Written in TypeScript (target ES2020, Node16 module resolution) and compiled to ESM-only JavaScript via tsc; there are no runtime dependencies at all. The types/standard.ts and types/other.ts data files are not hand-maintained — scripts/build.ts regenerates them by fetching the upstream mime-db JSON database, resolving type/extension conflicts with the mime-score package (preferring the higher-scoring entry per RFC 6838 facet rules), and writing the results back out through Prettier. Tooling is minimal and modern: TypeScript’s own compiler for builds, Prettier for formatting/linting (no ESLint despite a checked-in .eslintrc.cjs), and release-please for changelog/version automation on release.

Code Quality

Tests run via Node’s built-in node:test runner (test/mime.test.js, test/vendor.test.js) with a small shared test_util.js helper for table-driven assertions, plus a separate test/exports_test.sh that exercises the package’s export map directly. Coverage includes case-insensitivity, path/extension edge cases, Unicode whitespace in filenames, charset-parameter stripping, and both success and CLI subprocess paths — a comprehensive test suite for a library this size. TypeScript is run in strict mode, private class fields (#extensionToType) are used to genuinely encapsulate state rather than relying on convention, and CI (Mime CI GitHub Actions workflow) runs the full test suite across Node 18/20/22/24 on every push.

What Makes It Unique

Rather than hand-curating its MIME type tables, mime treats mime-db as an upstream data source and layers a build-time conflict-resolution pass (mime-score) on top of it, automatically demoting lower-priority types when multiple MIME types claim the same extension instead of letting the last one silently win. Pairing a frozen, dependency-free default export with an escape hatch — a mutable Mime class consumers can instantiate and define() themselves — gives it both a safe, tree-shakeable default and a documented path to customization, which is an uncommon combination among comparable extension-mapping libraries.

Used by 36 apps in this directory

TypeScript
94%
AGPL 3.0

Papra

Bookmarks Archiving

5,587

Self-hosted document archiving with email ingestion, OCR full-text search, and pluggable storage — store once, find anything.

View details
86
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 94%
Updated 3 days ago
JavaScript
98%
Apache 2.0

Parse Server

Databases · Developer Tools

21,401

Self-hosted Backend-as-a-Service for Node.js with REST, GraphQL, real-time Live Query, cloud code, and pluggable adapters for any infrastructure.

View details
98
Repo Health
81
Technical
70
Dependency
Built with
JavaScript 98%
Updated 3 days ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 3 days ago
TypeScript
81%
AGPL 3.0

Postiz

Automation · Social Media

37,683

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
92
Repo Health
70
Technical
63
Dependency
Built with
TypeScript 81%
JavaScript 11%
Updated 3 days ago
TypeScript
96%
Other

Refly

AI Development · Automation · No Code Platforms

7,537

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
68
Repo Health
76
Technical
63
Dependency
Built with
TypeScript 96%
Updated 5 days ago
TypeScript
97%
Apache 2.0

Unleash

Ab Testing Experimentation · Developer Tools · Devops

13,899

The open-source feature management platform that lets you ship code to production and control who sees it — without redeploying.

View details
91
Repo Health
84
Technical
69
Dependency
Built with
TypeScript 97%
Updated 3 days ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

Open-source AI code editor with direct LLM integration and data privacy

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 4 months ago
TypeScript
87%
Other

Webiny JS

Blogging · CMS · Ecommerce

8,047

Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.

View details
90
Repo Health
86
Technical
61
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 3 days ago
JavaScript
93%
BSD 3

xyops

Automation · Monitoring

6,291

A unified, self-hosted platform for job scheduling, visual workflow automation, server monitoring, alerting, and incident response — built for teams who demand full ownership of their operations stack.

View details
79
Repo Health
74
Technical
76
Dependency
Built with
JavaScript 93%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers