npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-http-support

v1.0.0

Published

![](https://img.shields.io/badge/express--http--support-1.0-green.svg?longCache=true)

Downloads

2

Readme

express-http-support

This is an Express middleware to make the Express response object hold all the (most widely known) HTTP status codes and HTTP headers, as methods.

1. Installation

~$ npm install -s express-http-support

2. Usage

1. Import the module and add the 2 middlewares (for the HTTP status codes and for the headers):
var express = require("express");

// 0) Instantiate an Express application:
var app = express();

// 1) Get the module:
var httpSupport = require("express-http-support");

// 2) Add all the HTTP status codes:
app.use(httpSupport.status.middleware);

// 3) Add all the HTTP headers:
app.use(httpSupport.headers.middleware); 
2. Access the HTTP status codes or headers from any middleware or controller directly:

Example of HTTP status code modification 1:

app.get("/", function(req, res, next) {
  res.statusOK().send("Normal response");
});

Example of HTTP status code modification 2:

app.get("/nocontent", function(req, res, next) {
  res.statusNoContent().send();
});

Example of HTTP header modification 1:

app.get("/referrer", function(req, res, next) {
  res.headerContentType("application/json").send("Content type altered");
});

Example of HTTP header modification 2:

app.get("/nocontent", function(req, res, next) {
  res.statusNoContent().send();
});

3. API Reference

Available HTTP status code methods:

app.get("/", function(request, response, next) {
	response.statusContinue();
	response.statusSwitchingProtocols();
	response.statusProcessing();
	response.statusEarlyHints();
	response.statusUnassigned();
	response.statusOK();
	response.statusCreated();
	response.statusAccepted();
	response.statusNonAuthoritativeInformation();
	response.statusNoContent();
	response.statusResetContent();
	response.statusPartialContent();
	response.statusMultiStatus();
	response.statusAlreadyReported();
	response.statusUnassigned();
	response.statusIMUsed();
	response.statusUnassigned();
	response.statusMultipleChoices();
	response.statusMovedPermanently();
	response.statusFound();
	response.statusSeeOther();
	response.statusNotModified();
	response.statusUseProxy();
	response.statusUnused();
	response.statusTemporaryRedirect();
	response.statusPermanentRedirect();
	response.statusUnassigned();
	response.statusBadRequest();
	response.statusUnauthorized();
	response.statusPaymentRequired();
	response.statusForbidden();
	response.statusNotFound();
	response.statusMethodNotAllowed();
	response.statusNotAcceptable();
	response.statusProxyAuthenticationRequired();
	response.statusRequestTimeout();
	response.statusConflict();
	response.statusGone();
	response.statusLengthRequired();
	response.statusPreconditionFailed();
	response.statusPayloadTooLarge();
	response.statusURITooLong();
	response.statusUnsupportedMediaType();
	response.statusRangeNotSatisfiable();
	response.statusExpectationFailed();
	response.statusUnassigned();
	response.statusMisdirectedRequest();
	response.statusUnprocessableEntity();
	response.statusLocked();
	response.statusFailedDependency();
	response.statusUnassigned();
	response.statusUpgradeRequired();
	response.statusUnassigned();
	response.statusPreconditionRequired();
	response.statusTooManyRequests();
	response.statusUnassigned();
	response.statusRequestHeaderFieldsTooLarge();
	response.statusUnassigned();
	response.statusUnavailableForLegalReasons();
	response.statusUnassigned();
	response.statusInternalServerError();
	response.statusNotImplemented();
	response.statusBadGateway();
	response.statusServiceUnavailable();
	response.statusGatewayTimeout();
	response.statusHTTPVersionNotSupported();
	response.statusVariantAlsoNegotiates();
	response.statusInsufficientStorage();
	response.statusLoopDetected();
	response.statusUnassigned();
	response.statusNotExtended();
	response.statusNetworkAuthenticationRequired();
	response.statusUnassigned();
	response.send("");
});

Available HTTP header methods:

app.get("/", function(request, response, next) {
	response.headerAccept("application/json");
	response.headerAcceptCharset("utf8");
	response.headerAcceptEncoding("utf8");
	response.headerAcceptLanguage("*");
	response.headerAcceptDatetime("*");
	response.headerAccessControlRequestMethod("*");
	response.headerAccessControlRequestHeaders("*");
	response.headerAuthorization("Basic blablabla");
	response.headerCacheControl("no-cache");
	response.headerConnection("*");
	response.headerCookie("*");
	response.headerContentLength("*");
	response.headerContentMD5("*");
	response.headerContentType("application/json");
	response.headerDate("*");
	response.headerExpect("*");
	response.headerForwarded("*");
	response.headerFrom("*");
	response.headerHost("*");
	response.headerIfMatch("*");
	response.headerIfModifiedSince("*");
	response.headerIfNoneMatch("*");
	response.headerIfRange("*");
	response.headerIfUnmodifiedSince("*");
	response.headerMaxForwards("*");
	response.headerOrigin("*");
	response.headerPragma("*");
	response.headerProxyAuthorization("*");
	response.headerRange("*");
	response.headerReferer ("*");
	response.headerTE("*");
	response.headerUserAgent("*");
	response.headerUpgrade("*");
	response.headerVia("*");
	response.headerWarning("*");
	response.headerUpgradeInsecureRequests("*");
	response.headerXRequestedWith("*");
	response.headerDNT("*");
	response.headerXForwardedFor("*");
	response.headerXForwardedHost("*");
	response.headerXForwardedProto("*");
	response.headerFrontEndHttps("*");
	response.headerXHttpMethodOverride("*");
	response.headerXATTDeviceId("*");
	response.headerXWapProfile("*");
	response.headerProxyConnection("*");
	response.headerXUIDH("*");
	response.headerXCsrfToken("*");
	response.headerXRequestID("*");
	response.headerXCorrelationID("*");
	response.headerAccessControlAllowOrigin("*");
	response.headerAccessControlAllowCredentials("*");
	response.headerAccessControlExposeHeaders("*");
	response.headerAccessControlMaxAge("*");
	response.headerAccessControlAllowMethods("*");
	response.headerAccessControlAllowHeaders("*");
	response.headerAcceptPatch("*");
	response.headerAcceptRanges("*");
	response.headerAge("*");
	response.headerAllow("*");
	response.headerAltSvc("*");
	response.headerCacheControl("*");
	response.headerConnection("*");
	response.headerContentDisposition("*");
	response.headerContentEncoding("utf8");
	response.headerContentLanguage("*");
	response.headerContentLength("*");
	response.headerContentLocation("*");
	response.headerContentMD5("*");
	response.headerContentRange("*");
	response.headerContentType("application/json");
	response.headerDate("*");
	response.headerETag("*");
	response.headerExpires("*");
	response.headerLastModified("*");
	response.headerLink("*");
	response.headerLocation("*");
	response.headerP3P("*");
	response.headerPragma("*");
	response.headerProxyAuthenticate("*");
	response.headerPublicKeyPins("*");
	response.headerRetryAfter("*");
	response.headerServer("*");
	response.headerSetCookie("*");
	response.headerStrictTransportSecurity("*");
	response.headerTrailer("*");
	response.headerTransferEncoding("*");
	response.headerTk("*");
	response.headerUpgrade("*");
	response.headerVary("*");
	response.headerVia("*");
	response.headerWarning("*");
	response.headerWWWAuthenticate("*");
	response.headerXFrameOptions("*");
	response.send("{}");
});

4. Conclusion

Following the same programmatic API that express brings by itself, where we can find the HTTP methods available as properties of the {Express Application} object, I wanted to expand the same idea to the HTTP status codes and the HTTP headers too, but in this case, in the {Express Response} object.

5. More

About: HTTP status codes

About: HTTP headers.