# http-codes

> Map of HTTP status messages to codes based on Node's built-in (inverse) map

Latest version **2.1.0** (published 2026-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install http-codes
pnpm add http-codes
yarn add http-codes
bun add http-codes
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-08-06 |
| First published | 2014-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ariel Flesler |
| Maintainers | flesler |
| Keywords | http, status, codes, messages, builtin, map, javascript, nodejs, node |

## Links

- npm: https://www.npmjs.com/package/http-codes
- Repository: https://github.com/flesler/node-http-codes
- Issues: https://github.com/flesler/node-http-codes/issues
- npm.io page: https://npm.io/package/http-codes

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2026-08-06
- 2.0.0 — 2026-08-06
- 1.0.0 — 2014-02-06

## README

# http-codes

Map of HTTP status messages to codes — the inverse of [Node's built-in `STATUS_CODES`](https://nodejs.org/api/http.html#httpstatuscodes).

Stays in sync with Node: when the runtime adds or renames a status, this package picks it up automatically.

[![NPM](https://nodei.co/npm/http-codes.png?compact=true)](https://npmjs.org/package/http-codes)

```bash
npm install http-codes
```

```js
import codes from 'http-codes'
// or
const codes = require('http-codes')

codes.OK          // 200
codes.NOT_FOUND   // 404
codes.IM_A_TEAPOT // 418
```

---

## Why use this

- **Ultra simple** — one small module, zero dependencies
- **Always current** — derived from Node's built-in map at load time
- **TypeScript types** included

---

## API

The module exports a plain object. Each key is the status message in `SCREAMING_SNAKE_CASE`; each value is the numeric code.

```js
import codes from 'http-codes'

if (res.statusCode === codes.NOT_FOUND) {
  // …
}
```

Keys are normalized from Node's messages: apostrophes removed, hyphens and spaces become underscores, then uppercased (`"Request Timeout"` → `REQUEST_TIMEOUT`).

The exact set of keys depends on your Node version. Run `npm test` to print the current map.

---

## Upgrading from 1.x

**No code changes needed** if you used `require('http-codes')` and property access — that is the entire 1.0.0 API and it is preserved in 2.0.0.

2.0.0 is a major release because of packaging (TypeScript, `dist/`, dual ESM/CJS, built-in types, tooling) and the long gap since 1.0.0 — not because the `require()` shape changed.

Full compatibility matrix, dependent-audit commands, and smoke tests: [docs/backwards-compatibility.md](docs/backwards-compatibility.md).

---

## License

MIT — see [LICENSE](LICENSE).

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