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.
#!/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-brkand not just plain
--inspectfor Chrome and PHPStorm scripts.
- For Chrome, follow these instructions.
- For PHPStorm read this and then do this: