HTTP Status Emojis
http-status-emojis is a minimalist JavaScript library that provides a direct mapping of common HTTP status codes to relevant Unicode emojis. Currently at version 2.2.0, it exposes a simple, immutable object where keys are numeric HTTP status codes (e.g., 200, 404, 500) and values are corresponding emojis (e.g., '✅', '❓', '💣'). The package is highly stable with a generally slow release cadence, typically updated to add new emojis or address minor issues rather than introduce breaking API changes. Its key differentiator is its single-purpose design, offering a straightforward and zero-dependency solution for visually representing HTTP statuses in contexts such as logs, command-line tools, or user interfaces where a quick, intuitive status indicator is beneficial.
Common errors
-
TypeError: Cannot read properties of undefined (reading '200')
cause The `http-status-emojis` module was not successfully imported or required, resulting in `statusEmojis` being undefined or null.fixEnsure the import/require statement is correct for your module system (CommonJS: `const statusEmojis = require('http-status-emojis');` or ESM: `import statusEmojis from 'http-status-emojis';`) and that the package is installed (`npm install http-status-emojis`). -
TypeError: statusEmojis is not a function
cause Attempting to call `statusEmojis` as a function, but it is an object containing emoji mappings.fixAccess status emojis as properties of the `statusEmojis` object using bracket notation (e.g., `statusEmojis[200]`) rather than calling it as a function.
Warnings
- gotcha The package does not have explicit ESM `exports` in its `package.json`. While it can be imported in ESM contexts via `import statusEmojis from 'http-status-emojis'`, this relies on Node.js's CJS interoperability. For strict ESM projects, be aware of potential tooling conflicts or different behavior in bundlers.
- gotcha Emojis may render differently across various operating systems, browsers, and terminal emulators. The visual appearance and sometimes even the meaning of an emoji can vary significantly, which is an inherent limitation of using Unicode emojis.
- gotcha Not every single HTTP status code has a specific, curated emoji. Attempting to access `statusEmojis[unknownCode]` for an unmapped code will return `undefined`. Always handle `undefined` results gracefully.
Install
-
npm install http-status-emojis -
yarn add http-status-emojis -
pnpm add http-status-emojis
Imports
- statusEmojis
import { statusEmojis } = require('http-status-emojis');const statusEmojis = require('http-status-emojis'); - statusEmojis (ESM)
import { statusEmojis } from 'http-status-emojis';import statusEmojis from 'http-status-emojis';
- Specific emoji access
const okEmoji = statusEmojis.200;
const okEmoji = statusEmojis[200];
Quickstart
import statusEmojis from 'http-status-emojis';
// Basic usage: retrieve emojis for common HTTP status codes
console.log(`HTTP 200 OK: ${statusEmojis[200]}`); // => HTTP 200 OK: ✅
console.log(`HTTP 201 Created: ${statusEmojis[201]}`); // => HTTP 201 Created: ✨
console.log(`HTTP 400 Bad Request: ${statusEmojis[400]}`); // => HTTP 400 Bad Request: ⁉️
console.log(`HTTP 404 Not Found: ${statusEmojis[404]}`); // => HTTP 404 Not Found: ❓
console.log(`HTTP 500 Internal Server Error: ${statusEmojis[500]}`); // => HTTP 500 Internal Server Error: 💣
// Handling an HTTP status code that might not have a specific emoji
const notImplemented = 501;
console.log(`HTTP ${notImplemented} Not Implemented: ${statusEmojis[notImplemented] || '🤷♀️ (No specific emoji)'}`);
// Iterating through all available status emojis
console.log('\nAll available HTTP status emojis:');
for (const code in statusEmojis) {
console.log(` ${code}: ${statusEmojis[code]}`);
}