A lightweight, developer-friendly toolkit for working with HTTP status codes and messages in Node.js and TypeScript β now with localization, subpath imports, and improved DX.
npm install http-status-toolkitStatusCodes.OK for 200)
getStatusMessage) to fetch messages by status code
bash
npm install http-status-toolkit
`
$3
`bash
yarn add http-status-toolkit
`
Using pnpm
`bash
pnpm add http-status-toolkit
`
TypeScript & Module Support
- β
Full TypeScript support with type safety and autocompletion
- β
Works in both ESM and CommonJS environments
---
How to use
`ts
import {
StatusCodes,
getStatusMessage,
} from 'http-status-toolkit';
// Get the status code number
console.log(StatusCodes.OK); // 200
// Get a short message (default)
console.log(getStatusMessage(StatusCodes.NOT_FOUND));
// Output: "Not Found"
// Get a detailed message (import detailed messages and pass variant)
import DetailedMessages from 'http-status-toolkit/messages-detailed';
console.log(getStatusMessage(StatusCodes.NOT_FOUND, { variant: DetailedMessages }));
// Output: "Not Found: The requested resource could not be found but may be available in the future."
// Get a localized message (import a language variant)
import BengaliMessages from 'http-status-toolkit/messages-bn';
console.log(getStatusMessage(StatusCodes.NOT_FOUND, { variant: BengaliMessages }));
// Output: (Not Found message in Bengali)
`
---
Whatβs included?
- StatusCodes: constants for all HTTP status codes
- StatusMessages: short messages for each code (English default)
- DetailedStatusMessages: longer, more detailed English messages
- getStatusMessage(code, options?): returns the message for a status code; optionally pass a { variant } to get localized or detailed messages
> Note:
> getStatusMessage returns the HTTP reason phrase for a status code.
> You can also use the alias getReasonPhrase, which behaves the same way.
---
Common HTTP Status Codes
| Code | Constant | Message |
| ---- | ------------ | ---------------- |
| 200 | OK | Request OK |
| 201 | CREATED | Resource created |
| 400 | BAD_REQUEST | Bad input |
| 401 | UNAUTHORIZED | Auth required |
| 403 | FORBIDDEN | Access denied |
| 404 | NOT_FOUND | Not found |
| 500 | SERVER_ERROR | Server crashed |
π See full list of status codes
π See status codes with detailed messages
---
Supported Languages (Localization)
You can import message variants for different languages:
| Language | Import Path | Docs File |
|-------------|-------------------------------------|-----------------------------------|
| English (default) | β | β |
| Detailed English | messages-detailed | detailed-status-messages.md |
| Bengali | messages-bn | bengali-status-messages.md |
| Chinese | messages-zh | chinese-status-messages.md |
| Hindi | messages-hi | hindi-status-messages.md |
| Arabic | messages-ar | arabic-status-messages.md |
| German | messages-de | german-status-messages.md |
| French | messages-fr | french-status-messages.md |
| Italian | messages-it | italian-status-messages.md |
| Spanish | messages-es | spanish-status-messages.md |
| Japanese | messages-ja | japanese-status-messages.md |
| Russian | messages-ru` | russian-status-messages.md |