# mime-types — card for AI agents

Utility for working with MIME types and file extensions.

Category: Utilities · npm package `mime-types` · latest version 3.0.2 (checked 2026-11-01)
Install: `npm install mime-types`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 61.6 (#907 of all tools, 108 of 408 in its category)
- Used in 22 public projects set up for AI coding agents (0.4%)
- Downloads last week: 414,101,665 (as of 2026-11-24), +40.6% over 4 weeks
- GitHub stars: 1,480 (as of 2026-11-24)
- Last push: 2026-06-02

## Often used with
esbuild 50.0%, date-fns 45.5%, cross-env 36.4%, Framer Motion 36.4%, lint-staged 36.4%, TypeScript 90.9%

## Links
- AgentGid page: https://agentgid.com/tools/mime-types/
- Homepage: https://github.com/jshttp/mime-types#readme
- Repository: https://github.com/jshttp/mime-types


## mime-types: the right file type for any file name

mime-types is a small free JavaScript package for Node.js servers. Give it a file name like report.pdf and it returns the type label browsers expect, such as application/pdf, or the other way round. Your server then sends files that open in the browser instead of downloading as unknown data.

### Where to use it
- Serve files with the right type: Your app sends uploaded files or generated reports from its own route; each one gets the matching Content-Type header, so a PDF opens in the browser tab.
- Accept only pictures in an upload form: Before saving an avatar, check that the file name ends in a picture type you allow and reject the others with a clear message. (idea, not from the official pages)
- Name files you download: Your app fetches a file from another service and only knows its type; mime-types gives the extension to save it under, such as .png or .pdf.
- A safe default for unknown files: Files with no or a strange extension get the generic binary type, so browsers download them instead of guessing.
- Mark text files as UTF-8: Markdown, CSV and other text files get charset=utf-8 added to their type, so accents and emoji show correctly.
- Set the type on cloud storage uploads: When your app puts files into cloud storage, pass the looked-up type along, so the public link opens a picture instead of downloading it. (idea, not from the official pages)

### How to start
- Add the package to your Node.js project (Node.js 18 or newer for version 3).

```
npm install mime-types
```

- Load it and look up types by file name or extension.

```
var mime = require('mime-types')
mime.lookup('file.html') // 'text/html'
mime.contentType('file.json') // 'application/json; charset=utf-8'
```


### License
Free to use, also in paid and closed-source products, under the MIT license. Keep the copyright and license notice when you pass the package's files on. Its type list, mime-db, is MIT as well.

### Good to know
- It reads only the file name, never the file itself; a renamed file passes as whatever its name says.
- Unknown names give false, not a default type, so your code has to supply the fallback.
- Version 3 needs Node.js 18 or newer and changed some answers, for example .xml and .rtf.
- The type list comes from the separate mime-db package and can change in minor updates; pin mime-db yourself if answers must never change.
- The latest version, 3.0.2, came out on 2025-11-20.

Checked 2026-11-10 against: https://github.com/jshttp/mime-types/blob/master/README.md, https://github.com/jshttp/mime-types/blob/master/HISTORY.md, https://github.com/jshttp/mime-types/blob/master/LICENSE, https://github.com/jshttp/mime-types/blob/master/index.js, https://github.com/jshttp/mime-db/blob/master/README.md, https://registry.npmjs.org/mime-types, https://registry.npmjs.org/mime-types/3.0.2, https://registry.npmjs.org/mime-db

### Mistakes to avoid
- Don't: mime.contentType('uploads/report.pdf') or any value that contains a slash → Do: mime.contentType(path.extname(file)) or mime.lookup(file) (contentType() treats anything with a slash as a ready type and returns it unchanged; in our run 'folder/.htaccess' came back as the "type".)
- Don't: res.setHeader('Content-Type', mime.lookup(name)) → Do: res.setHeader('Content-Type', mime.contentType(path.extname(name)) || 'application/octet-stream') (Unknown names give false, which is not a valid header value, and lookup() does not add charset=utf-8 for text.)
- Don't: mime.getType(name) or mime.getExtension(type) → Do: mime.lookup(name) and mime.extension(type) (getType and getExtension belong to the separate mime package; mime-types keeps the mime 1.x names.)
- Don't: Naming an MP3 download with mime.extension('audio/mpeg') → Do: Keep a small map for the types you care about (audio/mpeg -> mp3) and fall back to mime.extension() (extension() returns the first extension in mime-db's list; in our run audio/mpeg gave "mpga".)
- Don't: Expecting the same answers after upgrading from 2.x (for example text/xml for .xml) → Do: Re-check the types your app depends on after an upgrade to 3.x (Version 3.0.0 changed several answers to settle conflicts between sources.)

### Questions
- Does it check what is inside the file? No. It looks only at the extension in the name; for real content checks use a package that reads the file's first bytes, such as file-type.
- What does it return for a file it does not know? false. Add your own fallback, usually application/octet-stream.
- Where do the types come from? From mime-db, a list built from the official IANA register and the Apache and nginx web server lists.
- Is it the same as the mime package? No. Its calls match the old mime 1.x style (lookup, extension), not mime's newer getType and getExtension.
- Can I use it in a paid app? Yes. It is MIT licensed; keep the license notice when you ship its files.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
