Create a gist now

Instantly share code, notes, and snippets.

Embed
SSH into a Vagrant VM, such that Node.js can be debugged from a debugger or IDE in the host operating system. For some reason, port forwarding in the Vagrant file does not work. See https://groups.google.com/forum/#!topic/vagrant-up/RzPooJ0dp6Q
#!/bin/bash
# SSH into a Vagrant VM, forwarding ports in a way that allows node within Vagrant to be debugged by a debugger
# or IDE in the host operating system. Don't know why, but Vagrantfile port forwarding does not work.
# (https://groups.google.com/forum/#!topic/vagrant-up/RzPooJ0dp6Q)
/usr/bin/vagrant ssh-config > $TMPDIR/vagrant-ssh-config
ssh -F $TMPDIR/vagrant-ssh-config -L 5858:127.0.0.1:5858 default
rm $TMPDIR/vagrant-ssh-config
@Reggino

This comment has been minimized.

Show comment
Hide comment
@Reggino

Reggino Oct 9, 2013

Thanks, this helped me a lot.

Please note that this script is used on the host, when connecting to the guest. In my case, when connecting from a Windows environment, this can be achieved by configuring a SSH tunnel in Putty.

Reggino commented Oct 9, 2013

Thanks, this helped me a lot.

Please note that this script is used on the host, when connecting to the guest. In my case, when connecting from a Windows environment, this can be achieved by configuring a SSH tunnel in Putty.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Dec 23, 2014

This was super helpful for me as well. Thanks for figuring this out!

ghost commented Dec 23, 2014

This was super helpful for me as well. Thanks for figuring this out!

@Jonathan-Fan

This comment has been minimized.

Show comment
Hide comment
@Jonathan-Fan

Jonathan-Fan Mar 27, 2015

Thanks a lot, I am a newbie to nodejs, and this saved my week !

Thanks a lot, I am a newbie to nodejs, and this saved my week !

@zmwebdev

This comment has been minimized.

Show comment
Hide comment
@zmwebdev

zmwebdev Jun 18, 2015

Try this:

Vagrantfile:

config.vm.network :forwarded_port, host: 5858, guest: 5858
config.vm.network :forwarded_port, host: 8080, guest: 8080

SSH to Vagrant

$ vagrant ssh
$ cd /vagrant/....
$ node-inspector &
$ node --debug app.js

Access using:

http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858

Works Fine!!

Try this:

Vagrantfile:

config.vm.network :forwarded_port, host: 5858, guest: 5858
config.vm.network :forwarded_port, host: 8080, guest: 8080

SSH to Vagrant

$ vagrant ssh
$ cd /vagrant/....
$ node-inspector &
$ node --debug app.js

Access using:

http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858

Works Fine!!

@drewsonne

This comment has been minimized.

Show comment
Hide comment
@drewsonne

drewsonne Jul 10, 2015

I update this to take an argument as an arbitrary port, https://gist.github.com/drewsonne/747b1ce77cc2f912af0f

I update this to take an argument as an arbitrary port, https://gist.github.com/drewsonne/747b1ce77cc2f912af0f

@Mastergalen

This comment has been minimized.

Show comment
Hide comment
@Mastergalen

Mastergalen Jun 24, 2016

By default node-debug will bind to 127.0.0.1 which is loopback.

Use node-debug --web-host=0.0.0.0 to bind it to all interfaces. Forwarding port 8080 should now work.

By default node-debug will bind to 127.0.0.1 which is loopback.

Use node-debug --web-host=0.0.0.0 to bind it to all interfaces. Forwarding port 8080 should now work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment