# media-types

> handle multiple media types

Latest version **1.0.3** (published 2013-11-25) · 0 weekly downloads

## Install

```sh
npm install media-types
pnpm add media-types
yarn add media-types
bun add media-types
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2013-11-25 |
| First published | 2012-09-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Raynos |
| Maintainers | raynos |

## Links

- npm: https://www.npmjs.com/package/media-types
- Repository: https://github.com/Raynos/media-types
- Issues: https://github.com/Raynos/media-types/issues
- npm.io page: https://npm.io/package/media-types

## Dependencies (1)

- [negotiator](https://npm.io/package/negotiator.md) ~0.2.5

## Recent versions

- 1.0.3 (latest) — 2013-11-25
- 1.0.2 — 2013-11-25
- 1.0.1 — 2013-11-25
- 0.1.0 — 2012-09-23

## README

# media-types [![build status][1]][2]

handle multiple media types

## Example

```
var http = require("http")
var mediaTypes = require("media-types")

http.createServer(mediaTypes({
    "application/json": sendJson
    , "text/html": sendHtml
})).listen(8080)

function sendJson(req, res) { res.end("json") }

function sendHtml(req, res) { res.end("html") }
```

## Example with custom error handling

```
var http = require("http")
    , mediaTypes = require("media-types")

http.createServer(mediaTypes, {
    "application/json": sendJson
    , "text/html": sendHtml
    , default: function (req, res) {
        res.statusCode = 415
        res.end("I refuse to handle you")
    }
})).listen(8080)

function sendJson(req, res) { res.end("json") }

function sendHtml(req, res) { res.end("html") }
```

## Installation

`npm install media-types`

## Tests

`npm test`

## Contributors

 - Raynos

## MIT Licenced

  [1]: https://secure.travis-ci.org/Raynos/media-types.png
  [2]: http://travis-ci.org/Raynos/media-types

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