# mimetype

> A mime type catalog driven by filename extensions.

Latest version **0.0.8** (published 2015-11-17) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install mimetype
pnpm add mimetype
yarn add mimetype
bun add mimetype
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2015-11-17 |
| First published | 2012-09-13 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | R. S. Doiel |
| Maintainers | rsdoiel |

## Links

- npm: https://www.npmjs.com/package/mimetype
- Repository: https://github.com/rsdoiel/mimetype-js
- Homepage: https://github.com/rsdoiel/mimetype-js#readme
- Issues: http://github.com/rsdoiel/mimetype-js/issues
- npm.io page: https://npm.io/package/mimetype

## Recent versions

- 0.0.8 (latest) — 2015-11-17
- 0.0.7 — 2015-03-24
- 0.0.6 — 2015-01-29
- 0.0.5 — 2013-06-02
- 0.0.4 — 2012-10-08
- 0.0.3 — 2012-09-13

## README

[![build status](https://secure.travis-ci.org/rsdoiel/mimetype-js.png)](http://travis-ci.org/rsdoiel/mimetype-js)
mimetype-js
===========

# Overview

I find keep making these file extension lookup tables for mime types.  It's 
about time I put it in a module to save me the trouble.

# Examples

## general case

```JavaScript
	var mimetype = require('mimetype');
	
	console.log(mimetype.lookup("myfile.txt")); // Should display text/plain
	mimetype.set('.exotic', 'x-application/experimental'); // Add/update a mime type in the catalog
	console.log(mimetype.lookup("myfile.exotic")); // Should display x-application/experimental
	mimetype.del('.exotic'); // Removes the mime type from the catalog
	console.log(mimetype.lookup("myfile.exitoc")); // Should display false
	mimetype.forEach(function (ext, mime_type_string) {
		console.log(ext, mime_type_string); // Display the extension and matching mimetype in catalog
	});
```

## Special cases

Sometimes detecting by filename extensions isn't work and you want to 
default to a general purposes mime-type (e.g. text/plain, application/octet-stream).

```JavaScript
	var mimetype = require('mimetype');
	
	// This should display 0 (false)
	console.log(mimetype.lookup("filename.unknownMimeType");
	// This should display the string text/plain
	console.log(mimetype.lookup("filename.unknownMimeType", false, "text/plain");
	// This should display the string text/plain; charset=UTF-8
	console.log(mimetype.lookup("filename.unknownMimeType", "UTF-8", "text/plain");
```

## Using mimetype.js with MongoDB Shell

While this was implemented as a NodeJS module it also works under MongoDB's shell.
Instead of including with a "require" you would load the JavaScript file _load-mimetype.js_.

```JavaScript
	load("./extras/load-mimetype.js");
	print("Check the mime type of test.txt:" + MimeType.lookup("test.txt"));
```

This would display something like-

```shell
	MongoDB shell version: 2.2.0
	connecting to: test
	> load("./extras/load-mimetype.js");
	> print("Check the mime type of test.txt: " + MimeType.lookup("test.txt"));
	Check the mime type of test.txt: text/plain
	> 
```

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