
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
pretty-exceptions
Advanced tools
Pretty and more helpful uncaught exceptions, automatically.
const pretty = require('pretty-exceptions/lib')
const options = {
source: true,
native: true,
color: true,
cwd: process.cwd()
}
const output = pretty(new Error('foo'), options)
options
name | type | required | default | description |
---|---|---|---|---|
source | Boolean | ✖ | false | Show source code in stack |
native | Boolean | ✖ | false | Show native code in stack |
color | Boolean | ✖ | true | use ansi colors |
cwd | String | ✖ | process.cwd() | resolve file names relative to this path |
This is the preferred approach to best avoid mistakingly including into production builds
setup your NODE_PATH
environment variable
export NODE_PATH="$NODE_PATH:$(npm root -g)"
install pretty-exceptions
npm install --global pretty-exceptions
run your application with the --require
flag:
node --require pretty-exceptions my-app.js
# alternative modes (see below):
node --require pretty-exceptions/source my-app.js
Use Bash Aliases for less typing
# make a special alias for debugging
alias node-ex='node --require pretty-exceptions'
# or even better:
alias node='node --require pretty-exceptions/source'
To make this persistent, you need to add this into your
~/.bashrc
(or~/.bash_profile
).
env | default | description |
---|---|---|
PRETTY_EXCEPTIONS_SOURCE | 0 | Show source code in stack |
PRETTY_EXCEPTIONS_NATIVE | 0 | Show native code in stack |
PRETTY_EXCEPTIONS_COLOR | 1 | use ansi colors |
Require at the top-most entry point of your app:
require('pretty-exceptions')
// alternative modes (see below):
require('pretty-exceptions/source-native')
$ node --require pretty-exceptions my-app.js
Error: oh no! this is an error message!
│
└┬╼ /path/to/my-app.js
│
├──╼ someOtherFunction @ line 2:27
├──╼ someFunction @ line 6:3
└──╼ Object.<anonymous> @ line 9:1
Colors will vary based on your local terminal configuration
$ node --require pretty-exceptions/source my-app.js
# OR
$ PRETTY_EXCEPTIONS_SOURCE=1 node --require pretty-exceptions my-app.js
Error: oh no! this is an error message!
│
└┬╼ /path/to/my-app.js
│
├──╼ someOtherFunction @ line 2
│
│ function someOtherFunction () {
├╌╌╌╌╌╌╌╌╌╌╮
│ throw new Error('oh no! this is an error message!')
│ }
│
├──╼ someFunction @ line 6
│
│ function someFunction () {
├╌╌╌╌╮
│ someOtherFunction()
│ }
│
├──╼ Object.<anonymous> @ line 9
│
└╌╌╌╌╮
someFunction()
Colors will vary based on your local terminal configuration
$ node --require pretty-exceptions/native my-app.js
# OR
$ PRETTY_EXCEPTIONS_NATIVE=true node --require pretty-exceptions my-app.js
Error: oh no! this is an error message!
│
├─┬╼ /path/to/my-app.js
│ │
│ ├──╼ someOtherFunction @ line 2:27
│ ├──╼ someFunction @ line 6:3
│ └──╼ Object.<anonymous> @ line 9:1
│
├─┬╼ module.js
│ │
│ ├──╼ Module._compile @ line 571:32
│ ├──╼ Object.Module._extensions..js @ line 580:10
│ ├──╼ Module.load @ line 488:32
│ ├──╼ tryModuleLoad @ line 447:12
│ ├──╼ Function.Module._load @ line 439:3
│ └──╼ Module.runMain @ line 605:10
│
└┬╼ bootstrap_node.js
│
└──╼ run @ line 423:7
Colors will vary based on your local terminal configuration
$ node --require pretty-exceptions/source-native my-app.js
# OR
$ PRETTY_EXCEPTIONS_SOURCE=1 PRETTY_EXCEPTIONS_NATIVE=1 node --require pretty-exceptions my-app.js
Error: oh no! this is an error message!
│
├─┬╼ /path/to/my-app.js
│ │
│ ├──╼ someOtherFunction @ line 2
│ │
│ │ function someOtherFunction () {
│ ├╌╌╌╌╌╌╌╌╌╌╮
│ │ throw new Error('oh no! this is an error message!')
│ │ }
│ │
│ ├──╼ someFunction @ line 6
│ │
│ │ function someFunction () {
│ ├╌╌╌╌╮
│ │ someOtherFunction()
│ │ }
│ │
│ ├──╼ Object.<anonymous> @ line 9
│ │
│ └╌╌╌╌╮
│ someFunction()
│
│
├─┬╼ module.js
│ │
│ ├──╼ Module._compile @ line 571
│ ├──╼ Object.Module._extensions..js @ line 580
│ ├──╼ Module.load @ line 488
│ ├──╼ tryModuleLoad @ line 447
│ ├──╼ Function.Module._load @ line 439
│ └──╼ Module.runMain @ line 605
│
└┬╼ bootstrap_node.js
│
└──╼ run @ line 423
Colors will vary based on your local terminal configuration
Author: Ahmad Nassri • Twitter: @AhmadNassri
FAQs
Pretty and more helpful uncaught exceptions, automatically.
The npm package pretty-exceptions receives a total of 191 weekly downloads. As such, pretty-exceptions popularity was classified as not popular.
We found that pretty-exceptions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.