errorhandler
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
accepts | 1.3.8 | 5.28 kB | MIT | prod | |
escape-html | 1.0.3 | 1.87 kB | MIT | prod |
Errorhandler is a development-only error handler middleware for Node.js applications. It serves the purpose of providing complete information about errors during the development process. The middleware sends full error stack traces and internal details of any object passed to it when an error occurs back to the client. Content negotiation is used to return the error details in HTML, JSON, or plain text formats, depending on the type of object that caused the error.
Errorhandler can be easily used in your Node.js or Express.js application. First, download and install the Errorhandler module from the npm registry using the following command:
$ npm install errorhandler
After successful installation, you can import Errorhandler into your application using the require
function:
var errorhandler = require('errorhandler')
After importing you can use it as middleware in your application like this:
var express = require('express')
var errorhandler = require('errorhandler')
var app = express()
if (process.env.NODE_ENV === 'development') {
// only use in development
app.use(errorhandler())
}
You can further customize Errorhandler by passing in an options object. For example, if you want to output the errors to a different location during development other than the standard error output:
var express = require('express')
var errorhandler = require('errorhandler')
var notifier = require('node-notifier')
var app = express()
if (process.env.NODE_ENV === 'development') {
// only use in development
app.use(errorhandler({ log: errorNotification }))
}
function errorNotification (err, str, req) {
var title = 'Error in ' + req.method + ' ' + req.url
notifier.notify({
title: title,
message: str
})
}
For in-depth knowledge of how to use Errorhandler, the complete documentation is provided on the official Google source code errorhandler GitHub repository. The repository contains information on installation instructions, API usage, custom configurations, and sample examples. Browsing through the README file on this repository will provide a solid understanding of how to use and implement errorhandler in your Node.js applications for more efficient error handling during the development process.