Skip to content

Instantly share code, notes, and snippets.

@tamlyn
Last active March 14, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamlyn/8f9f0aa338fe528e1c7462d23e23192a to your computer and use it in GitHub Desktop.
Save tamlyn/8f9f0aa338fe528e1c7462d23e23192a to your computer and use it in GitHub Desktop.
Start debugging a running node process

Shows a list of all node processes and lets you select which one you want to debug.

For example

$ debug.sh
1) 73428 node webpack/webpackDevServer.js
2) 73494 node build/dist/server.js
Select which process to debug: █
#!/usr/bin/env bash
# Get info for all node processes
PROCESSES=$(ps | grep ' node ')
# Split on lines instead of spaces
IFS=$'\n'
# Change select prompt
PS3='Select which process to debug: '
# Prompt user for node process to signal
select PROCESS in $PROCESSES
do
# Split on spaces
IFS=' '
# Get array of parts, first part is PID
PARTS=( $PROCESS )
# Send signal to node process to start debugger
kill -SIGUSR1 $PARTS
break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment