Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HttpStatus
✓ import { HttpStatus } from 'http-status-ts';
✗ import HttpStatus from 'http-status-ts';
const HttpStatus = require('http-status-ts');
HttpStatus is a named export (an enum), not a default export. When using CommonJS, it must be accessed as a property of the required module.
httpStatusTextByCode
✓ import { httpStatusTextByCode } from 'http-status-ts';
✗ import httpStatusTextByCode from 'http-status-ts';
const httpStatusTextByCode = require('http-status-ts');
httpStatusTextByCode is a named export (a function). For CommonJS, it requires destructuring or property access from the module object.
All named exports
✓ import * as HttpStatusModule from 'http-status-ts';
This pattern allows accessing all named exports (e.g., `HttpStatusModule.HttpStatus`, `HttpStatusModule.httpStatusTextByCode`) under a single namespace. Useful if you need many exports from the module.
Demonstrates importing and utilizing both the `HttpStatus` enum to retrieve numeric codes and the `httpStatusTextByCode` function to obtain human-readable descriptions, including a conceptual example of their use in an HTTP response.
import { HttpStatus, httpStatusTextByCode } from 'http-status-ts';
// Get a status code's numeric value from the enum
const notFoundCode = HttpStatus.NOT_FOUND;
console.log(`The numeric code for 'Not Found' is: ${notFoundCode}`); // Output: 404
// Get the text description for a specific status code
const okText = httpStatusTextByCode(HttpStatus.OK);
console.log(`The text description for ${HttpStatus.OK} is: "${okText}"`); // Output: "OK"
// Example: Dynamically getting text for a user-input code (simulated)
const userProvidedCode = 500;
const errorMessage = httpStatusTextByCode(userProvidedCode);
console.log(`For code ${userProvidedCode}, the error message is: "${errorMessage}"`); // Output: "Internal Server Error"
// Example using status codes in a conceptual HTTP response
interface MockResponse {
status: (code: number) => { send: (message: string) => void };
}
const mockResponse: MockResponse = {
status: (code: number) => ({
send: (message: string) => {
console.log(`[HTTP Response Simulator] Status: ${code}, Body: ${message}`);
}
})
};
const createSuccess = HttpStatus.CREATED;
mockResponse.status(createSuccess).send(httpStatusTextByCode(createSuccess));
const clientError = HttpStatus.BAD_REQUEST;
mockResponse.status(clientError).send(httpStatusTextByCode(clientError));
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'OK')
The `HttpStatus` enum was not correctly imported or was imported as a default export, leading to it being `undefined` or a malformed object.
fixEnsure `HttpStatus` is imported as a named export: `import { HttpStatus } from 'http-status-ts';`. ReferenceError: httpStatusTextByCode is not defined
The `httpStatusTextByCode` function was not correctly imported or was not destructuring from the module in a CommonJS context.
fixUse a named import for ESM: `import { httpStatusTextByCode } from 'http-status-ts';`. For CJS: `const { httpStatusTextByCode } = require('http-status-ts');`. SyntaxError: Cannot use import statement outside a module
Attempting to use ES module `import` syntax in a file that is treated as a CommonJS module (e.g., a `.js` file without `"type": "module"` in `package.json`, or a `.ts` file compiled to CJS without proper transpilation setup).
fixEither convert your project to ES Modules by adding `"type": "module"` to your `package.json` (and renaming `.js` to `.mjs` if needed), or configure your TypeScript compiler to output ES Modules. Alternatively, use CommonJS `require()` syntax if your project is strictly CommonJS.
Audit
Dependencies
No dependency data recorded yet.