A tiny Express middleware that patches
reswith readable HTTP status shorthand getters — no moreres.status(404).json(...), justres.notFound.json(...).
npm install express-response-patchExpress is a peer dependency — make sure it's installed in your project.
const express = require("express");
const readableResponses = require("express-response-patch");
const app = express();
app.use(readableResponses());
app.get("/", (req, res) => {
res.ok.json({ message: "Hello world" }); // 200
});
app.get("/secret", (req, res) => {
res.forbidden.json({ error: "Access denied" }); // 403
});import readableResponses from "express-response-patch";| Property | Status Code |
|---|---|
res.continue |
100 |
res.ok |
200 |
res.created |
201 |
res.accepted |
202 |
res.noContent |
204 |
res.movedPermanently |
301 |
res.found |
302 |
res.notModified |
304 |
res.badRequest |
400 |
res.unauthorized |
401 |
res.paymentRequired |
402 |
res.forbidden |
403 |
res.notFound |
404 |
res.methodNotAllowed |
405 |
res.notAcceptable |
406 |
res.conflict |
409 |
res.gone |
410 |
res.unsupportedMediaType |
415 |
res.imATeapot |
418 |
res.unprocessableEntity |
422 |
res.tooManyRequests |
429 |
res.internalServerError |
500 |
res.notImplemented |
501 |
res.badGateway |
502 |
res.serviceUnavailable |
503 |
res.gatewayTimeout |
504 |
Each property returns this.status(code) — chainable just like res.status().
The raw status map is also exported:
const { HttpStatuses } = require("express-response-patch");
// { ok: 200, notFound: 404, ... }ESM:
import { HttpStatuses } from "express-response-patch";Full types are included via index.d.ts (CJS) and index.d.mts (ESM). The middleware augments express-serve-static-core's Response interface, so all shorthands appear on res automatically — no extra setup needed.
Breaking changes — see migration notes below.
The express-response-patch/statuses subpath export has been removed.
Import HttpStatuses directly from the package root instead:
- import HttpStatuses from "express-response-patch/statuses";
- const { HttpStatuses } = require("express-response-patch/statuses");
+ import { HttpStatuses } from "express-response-patch";
+ const { HttpStatuses } = require("express-response-patch");- Added
index.d.mts— dedicated ESM type declaration file usingexport default+ named exports, consumed whenmoduleResolutionresolves theimportcondition. index.d.tsnow correctly usesexport =(function + namespace merging) for CJS consumers — the previous mix ofexport defaultandexport =was invalid TypeScript.package.jsonexports map now nests"types"inside each condition block (require/import) as required by"moduleResolution": "NodeNext".
export type HttpStatusName // keyof typeof HttpStatuses
export type HttpStatusCode // numeric value type
export type HttpStatuses // Record<HttpStatusName, HttpStatusCode>Initial release.
MIT (c) Pratik Rathod