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 sdin
and stdout
?
The answer is yes, scripts called from within scripts have access to sdin
and stdout
.
Call your script from within a shell script.
Here's the wrapper script.
#!/bin/bash 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: