# mime-type

> the custom more powerful mime-type utility can work with mime-db.

Latest version **5.0.4** (published 2026-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install mime-type
pnpm add mime-type
yarn add mime-type
bun add mime-type
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.4 |
| Published | 2026-07-01 |
| First published | 2015-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 8.6 |
| Dependencies | 3 |
| Unpacked size | 408.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | riceball |
| Keywords | mime, mime-db, types |

## Links

- npm: https://www.npmjs.com/package/mime-type
- Repository: snowyu/mime-type.js
- npm.io page: https://npm.io/package/mime-type

## Dependencies (3)

- [path.js](https://npm.io/package/path.js.md) ^2.0.1
- [util-ex](https://npm.io/package/util-ex.md) ^2.6.0
- [picomatch](https://npm.io/package/picomatch.md) ^4.0.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 5.0.4 (latest) — 2026-07-01
- 5.0.0-alpha.2 (alpha) — 2024-06-08
- 5.0.3 — 2025-03-27
- 5.0.2 — 2025-01-24
- 5.0.1 — 2025-01-23
- 5.0.0 — 2024-08-29
- 5.0.0-alpha.1 — 2024-05-29
- 5.0.0-alpha.0 — 2024-05-21
- 4.0.0 — 2020-07-05
- 3.1.0 — 2020-07-04
- 3.0.7 — 2018-11-10
- 3.0.6 — 2018-11-10
- 3.0.5 — 2017-05-17
- 3.0.4 — 2015-07-12
- 3.0.3 — 2015-07-11
- … 4 more at https://npm.io/package/mime-type/versions

## README

# mime-type

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Test Coverage][coveralls-image]][coveralls-url]

The custom more powerful mime-type utility and built-in [mime-db](https://github.com/jshttp/mime-db) for Nodejs and Browser.

Compare With [mime-types](https://github.com/jshttp/mime-types), these features added:

- you can load mime-types via `mime = require('mime-type/with-db')` directly
- `mime = new Mime()` business, so you could do `lookup = mime.lookup.bind(mime)`.
- you can lookup the extension with glob match via `.lookup(extention)` functionality
- you can add the mime-type via `.define(type, mime)` functionality
- you can add many mime-type via `.load(mimes)` functionality
- you can search the mime-type via `.glob(pattern)` functionality
- you can remove a mime-type via `.delete(type)` functionality
- you can clear mime-types via `.clear(filter)` functionality
- `.exist(type)` functionality to check whether a mime-type is exist.
- `.extensions` will be deprecated, use `mime[type].extensions` instead.
- All functions return `undefined` if input is invalid or not found.

Otherwise, the API is compatible.

## Install

```sh
$ npm install mime-type
```

## API

```js
//create an empty mime-type:
import { MimeType } from 'mime-type'
const mime = new MimeType()
//or using mimeType which create an instance and load builtin mime-db directly.
import {mimeType} from 'mime-type/with-db'
//it equals to (you need `npm install mime-db` first):
import db from 'mime-db'
const mime = new MimeType(db)
```

All functions return `undefined` if input is invalid or not found.

### mime.lookup(path)

Lookup the content-type associated with a file.

```js
mime.lookup('json')             // 'application/json'
mime.lookup('.md')              // 'text/x-markdown'
mime.lookup('file.html')        // 'text/html'
mime.lookup('folder/file.js')   // 'application/javascript'
mime.lookup('folder/.htaccess') // false

mime.lookup('.og?')  // [ 'application/ogg', 'audio/ogg', 'audio/ogg', 'video/ogg' ]
mime.lookup('cats') // false
```

### mime.glob(pattern)

Return all MIME types which matching a pattern(See [Minimatch](https://github.com/isaacs/minimatch)).

```js
mime.glob('*/*')             // ['application/octet-stream']
mime.glob('*/*markdown')     // ['text/x-markdown']
mime.glob('text/j*')         // ['text/jade', 'text/jsx']
mime.glob('unknown/x')       // []
```

### mime.exist(type)

test whether a mime-type is exist.
It is an alias for `mime.hasOwnProperty`

```js
mime.exist('text/x-markdown') // true
mime.exist('unknown/xxx')     // false
```

### mime.define(type, object, duplicationWay?)

define a new mime-type. the duplicationWay is optional the process way of duplication extensions:

* mime.dupDefault: the default process way.
* mime.dupOverwrite: the news overwrite the olds
* mime.dupSkip: just skip it.
* mime.dupAppend: append the news to the exist extensions.

return the added extensions list if successful or `undefined`.

```js
mime.define('script/coffee', {
  extensions: ['coffee', 'litcoffee', 'coffee.md']
}, mime.dupAppend)
mime.lookup ('coffee') //[ 'text/coffeescript', 'script/coffee' ]
```

### mime.delete(type)

remove a specified mime-type

```js
mime.delete('script/coffee') //true
```

### mime.clear(filter)

clear all or specified mime-types

the filter could be a string pattern or a function

return the count of deleted mime-types.

```js
mime.clear() //clear all mime-types
mime.clear('text/*') //clear the specified mime-types
mime.clear(function(type, mime){
  return type.substr(0,5) === 'text/'
})
```

### mime.load(mimes)

load a lot of mime-types. return the count of loaded mime-types.

```js
mime.clear() //clear all mime-types
mime.load({
  'script/coffee': {
    extensions: ['coffee', 'coffee.md', 'litcoffee'],
    compressible: true,
    charset: 'utf-8',
    defaultExtension: 'coffee.md'
  },
  'script/python': {
    extensions: ['py', 'py.md', 'litpy'],
    compressible: true,
    charset: 'utf-8'
  }
})
```

### mime.contentType(type)

Create a full content-type header given a content-type or extension.

```js
mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json') // 'application/json; charset=utf-8'

// from a full path
mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'
```

### mime.extension(type)

Get the default extension for a content-type.

```js
mime.extension('application/octet-stream') // 'bin'
```

### mime.charset(type)

Lookup the implied default charset of a content-type.

```js
mime.charset('text/x-markdown') // 'UTF-8'
```

### var type = mime.types[extension]

A map of content-types by extension.

### [extensions...] = mime.extensions[type]

A map of extensions by content-type.

### var mimeObject = mime[type]

A map of mime object(IMimeType) by content-type.

```ts
export interface IMimeType {
  source: string;
  charset?: string;
  compressible?: boolean;
  extensions: string[]|string;
}
```

### mime.dup: DuplicationProcessWay

the default duplication process way.

See `mime.define`.

## Notes

* 4.0.0: nodejs >= 8.6
  * use micromatch instead of minimatch. It supports nodejs@8.6 above only.
* 3.0.0: nodejs <  8.6

## Credit

* [mime-types](https://github.com/jshttp/mime-types)
* [mime-db](https://github.com/jshttp/mime-db)

## License

[MIT](LICENSE)

[npm-image]: https://img.shields.io/npm/v/mime-type.svg
[npm-url]: https://npmjs.org/package/mime-type
[node-version-image]: https://img.shields.io/node/v/mime-type.svg
[node-version-url]: http://nodejs.org/download/
[coveralls-image]: https://img.shields.io/coveralls/snowyu/mime-type.js/master.svg
[coveralls-url]: https://coveralls.io/r/snowyu/mime-type.js
[downloads-image]: https://img.shields.io/npm/dm/mime-type.svg
[downloads-url]: https://npmjs.org/package/mime-type

---
_Source: https://npm.io/package/mime-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
