I am running a Node.js application within a Linux VM in Oracle VirtualBox. The port 5858
on the VM is forwarded to the port 5858
on the localhost.<
Instead of just
$ vagrant ssh
try
$ vagrant ssh -- -L 5858:127.0.0.1:5858
I also removed the line config.vm.network :forwarded_port, guest: 5858, host: 5858
from my Vagrantfile
and did a $ vagrant reload
.
In your vagrant box run
$ node --debug-brk path/to/file.js
Set up a Node.js Remote Debug Run/Debug configuration, defaults are fine (host 127.0.0.1 and port 5858).
Run the following from your HOST machine, not your vagrant box.
$ telnet 127.0.0.1 5858
You should get a response like
Type: connect
V8-Version: 3.14.5.9
Protocol-Version: 1
Embedding-Host: node v0.10.28
Content-Length: 0
If you don't then something wrong with the port forward. You could try a different port on the host end and update your webstorm Run/Debug configuration that was previously set up from port 5858 to the new port.
Now run the NodeJS debug configuration. It should immediately pick up the file and you'll be able to debug it.
I based my steps off of PHPStorm, but it should be the same. I'm assuming it'll work on all IntelliJ-based IDEs as long as you have the NodeJS plugin installed.