Skip to content

melvynkim/http-status-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published