mime-types

The ultimate JavaScript content-type utility for resolving MIME types from file extensions and paths.

Library
npm
v3.0.2
1,479 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
49 /100 Fair
Development Activity 8
Maintenance 32
Community 68
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 78
Code Quality 82
Innovation 88
Learning Curve 90

mime-types is a small, dependency-light Node.js utility that maps between file extensions and MIME content types. Built on top of the canonical mime-db dataset, it lets you look up the content type for a path, build a complete Content-Type header with the right charset, and find the default extension for a given type.

Unlike naive alternatives, it never guesses: every function returns false for unknown or invalid input, so you stay in full control of fallbacks. Its tiny, function-based API has made it a foundational building block across the Node.js ecosystem, powering frameworks like Express and countless file-serving and upload pipelines.

What You Get

  • Extension-to-MIME lookup via mime.lookup(path) that accepts bare extensions, dotted extensions, or full file paths
  • Full Content-Type header construction with mime.contentType(type), automatically appending the correct charset
  • Reverse mime.extension(type) lookup to get the default file extension for any MIME type
  • Charset resolution with mime.charset(type) plus direct mime.types and mime.extensions maps for custom logic

Common Use Cases

  • Setting the correct Content-Type response header when serving static files from a Node.js server
  • Validating and labelling uploaded files by mapping their extension to an expected MIME type
  • Choosing a sensible file extension when saving a downloaded resource identified only by its content type

Under The Hood

Architecture - The entire library lives in a single index.js that, at load time, calls populateMaps() to iterate every entry in the mime-db database and build two lookup tables on the exported object: types (extension to MIME type) and extensions (MIME type to extension list). Public functions lookup, contentType, extension, and charset are thin readers over these maps, with lookup normalizing input via Node’s path.extname('x.' + path) trick and a shared EXTRACT_TYPE_REGEXP stripping parameters from content types. When two types claim the same extension, _preferredType() in mimeScore.js resolves the conflict deterministically.

Tech Stack - Plain CommonJS JavaScript targeting Node.js >= 18 with a single runtime dependency, mime-db (^1.54.0), which supplies the underlying type data. mimeScore.js is a back-ported, dependency-free scoring function. Development tooling uses Mocha and nyc for tests and coverage, and ESLint with the Standard config for linting; there is no build step or transpilation.

Code Quality - The codebase is small, readable, and thoroughly covered by a 247-line Mocha suite in test/test.js exercising every public function across valid, invalid, and edge-case inputs. Input guards consistently reject non-string arguments by returning false, and functions are documented with JSDoc annotations. A small amount of transitional legacy code (_preferredTypeLegacy, _extensionConflicts) remains from a scoring migration.

API Design - The public surface is intentionally minimal: four functions plus two data maps, all destructurable directly from the module because nothing is stateful or class-based. Every function follows the same contract of returning false on failure, which makes fallback handling explicit and predictable. The API is deliberately compatible with the older mime@1.x module while removing its implicit fallbacks, and the README documents each function with concrete examples.

Used by 41 apps in this directory

Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,443

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
57
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 2 months ago
TypeScript
91%
Other

FastGPT

AI Agents · AI Development

29,900

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
66
Dependency
Built with
TypeScript 91%
Updated 6 days ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
TypeScript
63%
MIT

Ghost

Blogging · CMS

55,598

Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.

View details
96
Repo Health
85
Technical
64
Dependency
Built with
TypeScript 63%
JavaScript 35%
Updated 1 weeks ago
TypeScript
62%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,978

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 62%
Svelte 34%
Updated 1 weeks ago
Vue
50%
GPL 3.0

IT-Tools

Developer Tools

40,954

A unified collection of 88 web-based developer utilities — from JSON formatting to subnet calculation — all self-hostable, keyboard-searchable, and offline-ready.

View details
60
Repo Health
74
Technical
63
Dependency
Built with
Vue 50%
TypeScript 48%
Updated 1 weeks ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,338

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
99%
AGPL 3.0

Manage

Collaboration · Project Management

71

Self-hosted, open-source project management with tasks, calendars, docs, and real-time team collaboration.

View details
33
Repo Health
57
Technical
71
Dependency
Built with
TypeScript 99%
Updated 2 months ago
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,418

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated 6 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