Debugging a Running Nodejs Process In Vagrant

Software Contributor Documentation Table of Contents

There are some cases where you’d like to debug a running nodejs process running on a vagrant node.

This guide will walk through that process.

Once the process is in debug mode, Connections are possible via the browser or cli.

Browser

  1. Put the process into debug mode by sending a USR1 signal:

    systemctl kill -s SIGUSR1 SERVICE_NAME_HERE
    
  2. Install node-inspector on the vagrant node.

    npm i -g node-inspector
    
  3. start node-inspector:

    node-inspector
    
  4. On the host, connect to node-inspector using the ip address the vagrant node is running on (likely 0.0.0.0) and the port node-inspector has started on (likely 8080) using chrome.

  5. This should load the app in an old version of devtools and will halt the code at first execution.

CLI

  1. Put the process into debug mode by sending a USR1 signal:

    systemctl kill -s SIGUSR1 SERVICE_NAME_HERE
    
  2. Get the status output of the main service and note the main PID.

    systemctl status SERVICE_NAME_HERE
    
  3. Start the debugger

    node debug -p PID_HERE