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

v1.2.0

Published

Simple response statuses for Express 4.x

Downloads

12

Readme

Express Statuses

A very simple collection of statuses suitable to be used with the express-errorlog package.

Install and use

Install as usual with NPM:

npm install --save express-statuses

Then use it in your express app!

var S = require('express-statuses');
...
app.get('/foobar', function(req, res, next) {
  next(S.BAD_REQUEST);
})

The application error handler will see an object containing the following:

app.use(function(err, req, res, next) {
  // err will be { status: 400, message: 'Bad Request' }
  ...
})

A handy collection of status codes can also be accessed via the C sub-object:

app.post('/collection', function(req, res, next) {
  ...
  res.sendStatus(S.C.CREATED);
})

Getting statuses

Statuses can be referenced by name:

S.NOT_FOUND;

Or can be accessed by status code:

S(404);

All returned statuses can be passed to next(...) as-is or (being functions) can be used to further customize what is passed to the error handler.

Customization and inclusion can be done in few ways:

Messages

Messages can be overridden by simply invoking a status as a function:

next(S.NOT_FOUND('Something is amiss'));

will result in the error handler receiving the following as its first parameter:

{
  "status": 404,
  "message": "Something is amiss"
}

Errors

Errors can be nested for further logging by the error handler:

try {
  ...
} catch (error) {
  next(S.BAD_REQUEST(error));
}

will result in the error handler receiving the following as its first parameter:

{
  "status": 400,
  "message": "Bad Request"
  "error": ... // reference to the error for logging
}

Multiple overrides

For better express-errorlog integration, a number of parameters can be specified as options:

next(S.UNAUTHORIZED({
  message: 'No way I am letting you in',
  details: { key: 'Some extra stuff here' }
  error: myCaughtException
}));

will result in the error handler receiving the following as its first parameter:

{
  "status": 400,
  "message": "No way I am letting you in",
  "details": { "key": "Some extra stuff here" }
  "error": // reference to myCaughtException
}

Statuses

Listed here are all currently configured statuses:

  • Informational
    • CONTINUE: 100
    • SWITCHING_PROTOCOLS: 101
    • PROCESSING: 102
  • Successful
    • OK: 200
    • CREATED: 201
    • ACCEPTED: 202
    • NON_AUTHORITATIVE_INFORMATION: 203
    • NO_CONTENT: 204
    • RESET_CONTENT: 205
    • PARTIAL_CONTENT: 206
    • MULTI_STATUS: 207
    • ALREADY_REPORTED: 208
    • IM_USED: 226
  • Redirection
    • MULTIPLE_CHOICES: 300
    • MOVED_PERMANENTLY: 301
    • FOUND: 302
    • SEE_OTHER: 303
    • NOT_MODIFIED: 304
    • USE_PROXY: 305
    • _UNUSED_: 306
    • TEMPORARY_REDIRECT: 307
    • PERMANENT_REDIRECT: 308
  • Client Errors
    • BAD_REQUEST: 400
    • UNAUTHORIZED: 401
    • PAYMENT_REQUIRED: 402
    • FORBIDDEN: 403
    • NOT_FOUND: 404
    • METHOD_NOT_ALLOWED: 405
    • NOT_ACCEPTABLE: 406
    • PROXY_AUTHENTICATION_REQUIRED: 407
    • REQUEST_TIMEOUT: 408
    • CONFLICT: 409
    • GONE: 410
    • LENGTH_REQUIRED: 411
    • PRECONDITION_FAILED: 412
    • PAYLOAD_TOO_LARGE: 413
    • URI_TOO_LONG: 414
    • UNSUPPORTED_MEDIA_TYPE: 415
    • RANGE_NOT_SATISFIABLE: 416
    • EXPECTATION_FAILED: 417
    • I_AM_A_TEAPOT: 418
    • UNPROCESSABLE_ENTITY: 422
    • LOCKED: 423
    • FAILED_DEPENDENCY: 424
    • UNORDERED_COLLECTION: 425
    • UPGRADE_REQUIRED: 426
    • PRECONDITION_REQUIRED: 428
    • TOO_MANY_REQUESTS: 429
    • REQUEST_HEADER_FIELDS_TOO_LARGE: 431
    • UNAVAILABLE_FOR_LEGAL_REASONS: 451
  • Server Errors
    • INTERNAL_SERVER_ERROR: 500
    • NOT_IMPLEMENTED: 501
    • BAD_GATEWAY: 502
    • SERVICE_UNAVAILABLE: 503
    • GATEWAY_TIMEOUT: 504
    • HTTP_VERSION_NOT_SUPPORTED: 505
    • VARIANT_ALSO_NEGOTIATES: 506
    • INSUFFICIENT_STORAGE: 507
    • LOOP_DETECTED: 508
    • BANDWIDTH_LIMIT_EXCEEDED: 509
    • NOT_EXTENDED: 510
    • NETWORK_AUTHENTICATION_REQUIRED: 511

License (MIT)

Copyright (c) 2015 USRZ.com and Pier Paolo Fumagalli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.