I use 'forever' to run my application. I want to attach to the running environment to inspect my application. So what can I do?
Open up Preferences > Settings and in the search box type in “node debug”. Under the Extensions tab there should be one extension titled “Node debug”. From here, click the first box: Debug > Node: Auto Attach and set the drop down to “on”. You're almost ready to go now.
When debugging in Node. js, we add a breakpoint by adding the debugger keyword directly to our code. We can then go from one breakpoint to the next by pressing c in the debugger console instead of n . At each breakpoint, we can set up watchers for expressions of interest.
Starting from Node 6.3, node has a built-in debugger that can be triggered (even in a production app) by doing:
kill -USR1 <node-pid>
The node process will spit out something like this:
Debugger listening on ws://127.0.0.1:9229/f3f6f226-7dbc-4009-95fa-d516ba132fbd For help see https://nodejs.org/en/docs/inspector
chrome://inspect
on http://host.domain:9229
.If you cannot connect via a browser (e.g. the server is in a firewalled production cluster), you can activate a REPL to inspect over the command line:
node inspect -p <node-pid>
ssh -nNTL 9229:localhost:9229 <username>@<your_host> -i <keyfile>.pem
) and you'll find your script under chrome://inspect
after a few seconds.Prior to this version, node-inspector
was a separate tool for debugging Node processes. However, as documented on its own page, it is mostly deprecated as the now-bundled debugger is actively maintained and provides more advanced features. For more information on this change, see this thread.
From http://nodejs.org/api/debugger.html:
Advanced Usage
The V8 debugger can be enabled and accessed either by starting Node with the --debug command-line flag or by signaling an existing Node process with SIGUSR1.
Find the PID of your node
process and then sending SIGUSR1
should do the trick:
kill -s SIGUSR1 nodejs-pid
Then run node-inspector
and browse to the URL it indicates. More in this tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With