Giter Club home page Giter Club logo

debug-error-middleware's Introduction

Express/Koa error handling middleware

Build Status

Better context information for NodeJS Errors during development. The middleware parses potential errors that occur during a request/response cycle and display the stack trace plus additional context in the response.

Features:

  • Stack traces + collapsable code (snippets)
  • Sourcemaps
  • Environment variables
  • Request information

Example Page

Currently we support these two HTTP frameworks:

  • Express
  • Koa

Setup

$ npm install debug-error-middleware

Never enable the DEBUG middleware in a production environment. This could result in leaking sensitive information (e.g. ENV variables). The middleware throws an error if you try to load it with NODE_ENV set to "production".

Express

The debug middleware should be loaded first so we can catch errors from all other middleware.

var debugMiddleware = require('debug-error-middleware').express;

var app = express();

if (process.env.NODE_ENV === 'development') {
  app.use(debugMiddleware());
}

Koa

var debugMiddleware = require('debug-error-middleware').koa;

var app = new Koa();

if (process.env.NODE_ENV === 'development') {
  app.use(debugMiddleware());
}

Source Map Support

Even though it is not desirable to run transpiled source code inside the node js runtime, you often do not escape the use of it because of Server Side Rendering applications. debug-error-middleware automatically supports sourcemaps. This will result in stack traces that are easier to interpret. You can disable source map support through a configuration option.

Configuration

The following configuration options are available:

{
  theme: 'okaidia', // The prismjs theme to use
  disabledForXHR: true // Disable the middleware for XHR requests
  disableSourceMapSupport: false // Disables support for sourcemaps
}

debug-error-middleware's People

Contributors

ersoma avatar matthisk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.