Skip to content

Instantly share code, notes, and snippets.

@hapticdata
Last active August 29, 2015 13:56
Show Gist options
  • Save hapticdata/9163842 to your computer and use it in GitHub Desktop.
Save hapticdata/9163842 to your computer and use it in GitHub Desktop.
easy node and node-global debugging. 2 functions for your .bashrc
# put these in your ~/.bashrc and start a new shell to receive these commands
# requires node-inspector, install: npm install -g node-inspector
# start node-inspector and debug node app
# example: debug-node --open app.js --port=3000
function debug-node () {
# start node-inspector as a background-process
node-inspector &
# grab last PID to kill process later
INSPECTOR_PID=$!
# optionally open in browser
if [ $1 = "--open" ]; then
open "http://localhost:8080/debug?port-5858"
shift
fi
# next arg should be the name of the global app i.e. "grunt"
APP=$1
shift
# find the app in path with which, forward next args
node --debug-brk $APP $@
# kill node-inspector when done
kill $INSPECTOR_PID
}
# example: debug-node-global --open grunt jshint
# debug a node cli app with node-inspector
function debug-node-global () {
# start node-inspector as a background-process
node-inspector &
# grab last PID to kill process later
INSPECTOR_PID=$!
# optionally open in browser
if [ $1 = "--open" ]; then
open "http://localhost:8080/debug?port-5858"
shift
fi
# next arg should be the name of the global app i.e. "grunt"
APP=$1
shift
# find the app in path with which, forward next args
node --debug-brk $(which $APP) $@
# kill node-inspector when done
kill $INSPECTOR_PID
}
#too long? alias it:
#alias dng='debug-node-global'
#alias dn='debug-node'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment