Nothing Particularly Magnificent

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

errhandler

0.0.3 • Public • Published

NPM   Build Status

errhandler


Error handler for Node.js application http server

© Pradeep Mishra, Licensed under the MIT-LICENSE

Example usage

As a middleware for express, connect like node framework

var app = express();
var errHandler = require("errhandler");
 
// optional 
errHandler.error(function(err, req, res){
    // this.error, this.request, this.response is equal to err, req, res in arguments
    this.response.send(200, "oops!" + err.stack);
});
 
app.use(errHandler.middleWare);
 
app.get('/', function(req,res){
    process.nextTick(function(){
        throw new Error("my bad");
    });
});
 
app.listen(3000);
 

As a handler for core node.js http server

var http = require('http');
var errHandler = require("errhandler");
 
http.createServer(function(req, res) {
    var handler = errHandler.handler(req, res);
    
    // optional 
    handler.error(function(err, req, res){
        res.statusCode = 500;
        res.setHeader('content-type', 'text/html');
        res.end(err.stack);
    });
    
    handler.run(function(){
        throw new Error('my error');
    });
    
}).listen(3000);
 
npm install errhandler --save

install

npm i errhandler

Downloadsweekly downloads

9

version

0.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability