There are a number of debugging options open to NodeJS developers when running the server locally however, I struggled to find reliable instructions for me to debug a nodeJS application running on a Vagrant server. The following steps were required when using the server from https://github.com/semmypurewal/node-dev-bootstrap
1) Update the Vagrantfile configuration to forward ports 8080, 5858 to the host. Locate your Vagrant folder for your VM project and edit the
Vagrantfile enter the following values to open the ports to your host machine.
config.vm.forward_port 8080, 8080
config.vm.forward_port 5858, 5858
2) You will need to do a
vagrant halt and then a
vagrant up to restart with these configuration changes.
3) Next you will need to install the node-inspector tool that allows you to debug your nodeJS application. This is done by running the following command inside your vagrant VM.
sudo npm install -g node-inspector (It had to be run as sudo as it was complaining if this wasn’t done as admin)
4) Launch the application that in my situation is located at
~/app/app.js using the command
node-debug --debug-port 5858 app/app.js
5) The debugger should now be available at this URL http://localhost:8080/debug?port=5858
6) The application is halted on the first statement and therefore you need to launch the debugger and click sources then continue to start the application.
7) Once it is up and running you can then set breakpoints and debug your nodeJS application running on your Vagrant server.