New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

http-status-node

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-status-node

Http error wrapper

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

HTTP statuses for Node

http-status-node is a node wrapper for http status codes.

Usage

Require this module in your code and get a status object by key. Status objects contain code, message and createError method to create convenient node.js Error instance with all status data included.

Example


const express = require('express');
const  Q = require('q');
const HTTP_STATUSES = require('http-status-node');
const app = express();

app.get('/', function (req, res) {
  Q
    .try(function () {
      if (!req.param('ok')) {
        throw HTTP_STATUSES.BAD_REQUEST.createError("Not ok");
      }
      res.send("ok", HTTP_STATUSES.OK.code);
    })
    .catch(function(err) {
      res.send(err.message, err.httpStatus.code);
    });
});

const  server = app.listen(3000, function() {
  console.log('Listening on port %d', server.address().port);
});

Keywords

node.js

FAQs

Package last updated on 17 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts