Debugging a nodejs cli script with --inspect
NodeJS scripts from the CLI can be difficult to debug. Often, one doesn't want to modify the core processes.
I found the easiest way to hit a breakpoint was to create a shell wrapper.
But I was worried... would my code have access to
The answer is yes, scripts called from within scripts have access to
Call your script from within a shell script.
Here's the wrapper script.
exec node --inspect-brk=9229 ./myscript.js
Here are some notes:
- In this case, I am debugging on port
9229. You can use whatever port you like.
- You need to use
--inspect-brk and not just plain
--inspect for Chrome and PHPStorm scripts.
- For Chrome, follow these instructions.
- For PHPStorm read this and then do this:
About the Author
Hi. My name is Jeremiah John. I'm a sf/f writer and activist.
I just completed a dystopian science fiction novel. I run a website which I created that connects farms with churches, mosques, and synagogues to buy fresh vegetables directly and distribute them on a sliding scale to those in need.
In 2003, I spent six months in prison for civil disobedience while working to close the School of the Americas, converting to Christianity, as one does, while I was in the clink.