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-code

v1.0.0

Published

Adds methods to Express responses for dispatching HTTP status.

Downloads

4

Readme

express-http

Adds methods to Express responses for dispatching HTTP status.

Installation

$ npm i -s express-http-codes

Why?

To standarize basic HTTP response dispatching across files and applications.

The following HTTP statuses are already supported:

  • 100: Continue
  • 101: Switching protocols
  • 200: OK
  • 201: Created
  • 202: Accepted
  • 203: Non-authoritative information
  • 204: No content
  • 205: Reset content
  • 206: Partial content
  • 300: Multiple choices
  • 301: Moved permanently
  • 302: Moved temporarily
  • 303: See other
  • 304: Not modified
  • 305: Use proxy
  • 306: Unused
  • 307: Temporary redirect
  • 400: Bad request
  • 401: Unauthorized
  • 402: Payment required
  • 403: Forbidden
  • 404: Not found
  • 405: Method not allowed
  • 406: Not acceptable
  • 407: Proxy authentication required
  • 408: Request timeout
  • 409: Conflict
  • 410: Gone
  • 411: Length required
  • 412: Precondition failed
  • 413: Request entity too large
  • 414: Request-URI yoo long
  • 415: Unsupported media type
  • 416: Requested range not satisfiable
  • 417: Expectation failed
  • 426: Upgrade required
  • 428: Precondition required
  • 429: Too many requests
  • 431: Request header fields too large
  • 500: Internal server error
  • 501: Not implemented
  • 502: Bad gateway
  • 503: Service unavailable
  • 504: Gateway timeout
  • 505: HTTP version not supported
  • 511: Network authentication required

Usage

const expressHttp = require("express-http-codes");

/////////////////////////////////////////////
// In 1 step:
const express = expressHttp(require("express"));
// Alternatively, in 2 steps:
const express = require("express");
expressHttp(express);
/////////////////////////////////////////////

const app = express();

app.get("/success", (rq, rs) => rs.httpSuccess({ message: "This is a success" }, 200));
/* 

--- Returns: ---

{ 
	success: true, 
	code: 200,
	status: "OK",
	message: "This is a success"
}

*/
app.get("/error/404", (rq, rs) => rs.httpError({ message: "This is an error" }, 404));
/* 

--- Returns: ---

{ 
	error: true, 
	code: 404,
	status: "Not found",
	message: "This is an error"
}

*/
app.get("/error/custom", (rq, rs) => rs.httpError({ message: "This is an error" }, 901));
/* 

--- Returns: ---

{ 
	error: true, 
	code: 901,
	status: "Custom error",
	message: "This is an error"
}

*/
const server = app.listen(8080, () => console.log("Server listening."));

By default, if you use httpSuccess({...}) without code, it will respond a 200: OK.

By default, if you use httpError({...}) without code, it will respond a 400: Bad request.

Tests

$ npm run test

Versioning

This project adheres to the Semmantic Versioning 2.0.0.

Issues

You can send your issues here.

Contributions

As I do not have a job, I do not practice this part of "collective" coding, but I guess you can create your own branches.

License

This project is under WTFPL.