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

@kalkuz/express-respond-status

v1.0.1

Published

A quick-use and minimal response utility for all status codes

Downloads

65

Readme

npm version

Express Respond Status

Express Respond Status is a middleware for Express that adds response methods using the response object. This method allows you to easily send a response with a status code and a JSON body. It provides explanatory method names for each status code.

Installation

You can install this package using npm:

npm install @kalkuz/express-respond-status

Using yarn:

yarn add @kalkuz/express-respond-status

Dependencies

Express Respond Status only depends on Express.

Usage

Importing The Package

import Respond from '@kalkuz/express-respond-status';

Responding Requests

Example success responses:

// HTTP 200
Respond.OK(res, { somedata: 'somevalue' }, 'Any response message here');
// HTTP 201
Respond.Created(res, { somedata: 'somevalue' }, 'Any response message here');
// HTTP 202
Respond.Accepted(res, { somedata: 'somevalue' }, 'Any response message here');

Example error responses:

// HTTP 400
Respond.BadRequest(res,  { somedata: 'somevalue' }, 'Any response message here');
// HTTP 401
Respond.Unauthorized(res,  { somedata: 'somevalue' }, 'Any response message here');
// HTTP 403
Respond.Forbidden(res,  { somedata: 'somevalue' }, 'Any response message here');

Notes

  • The data parameter is optional. If you don't want to send any data, you can pass null or undefined as the second parameter.

  • The message parameter is optional. If you don't want to send any message, you can pass null or undefined as the third parameter.

Available Methods

HTTP Status Code | Method Usage --- | --- 100 | Continue(res, data, message) 101 | SwitchingProtocols(res, data, message) 102 | Processing(res, data, message) 103 | EarlyHints(res, data, message) 200 | OK(res, data, message) 201 | Created(res, data, message) 202 | Accepted(res, data, message) 203 | NonAuthoritativeInformation(res, data, message) 204 | NoContent(res, data, message) 205 | ResetContent(res, data, message) 206 | PartialContent(res, data, message) 207 | MultiStatus(res, data, message) 208 | AlreadyReported(res, data, message) 226 | IMUsed(res, data, message) 300 | MultipleChoices(res, data, message) 301 | MovedPermanently(res, data, message) 302 | Found(res, data, message) 303 | SeeOther(res, data, message) 304 | NotModified(res, data, message) 305 | UseProxy(res, data, message) 306 | Unused(res, data, message) 307 | TemporaryRedirect(res, data, message) 308 | PermanentRedirect(res, data, message) 400 | BadRequest(res, data, message) 401 | Unauthorized(res, data, message) 402 | PaymentRequired(res, data, message) 403 | Forbidden(res, data, message) 404 | NotFound(res, data, message) 405 | MethodNotAllowed(res, data, message) 406 | NotAcceptable(res, data, message) 407 | ProxyAuthenticationRequired(res, data, message) 408 | RequestTimeout(res, data, message) 409 | Conflict(res, data, message) 410 | Gone(res, data, message) 411 | LengthRequired(res, data, message) 412 | PreconditionFailed(res, data, message) 413 | PayloadTooLarge(res, data, message) 414 | URITooLong(res, data, message) 415 | UnsupportedMediaType(res, data, message) 416 | RangeNotSatisfiable(res, data, message) 417 | ExpectationFailed(res, data, message) 418 | ImATeapot(res, data, message) 421 | MisdirectRequest(res, data, message) 422 | UnprocessableEntity(res, data, message) 423 | Locked(res, data, message) 424 | FailedDependency(res, data, message) 425 | TooEarly(res, data, message) 426 | UpgradeRequired(res, data, message) 428 | PreconditionRequired(res, data, message) 429 | TooManyRequests(res, data, message) 431 | RequestHeaderFieldsTooLarge(res, data, message) 451 | UnavailableForLegalReasons(res, data, message) 500 | InternalServerError(res, data, message) 501 | NotImplemented(res, data, message) 502 | BadGateway(res, data, message) 503 | ServiceUnavailable(res, data, message) 504 | GatewayTimeout(res, data, message) 505 | HTTPVersionNotSupported(res, data, message) 506 | VariantAlsoNegotiates(res, data, message) 507 | InsufficientStorage(res, data, message) 508 | LoopDetected(res, data, message) 510 | NotExtended(res, data, message) 511 | NetworkAuthenticationRequired(res, data, message)

License

MIT License