I have a windows box and a VM running CentOS. Does anyone happen to know how I can debug a node CLI script (which doesn't open a port) using PHPStorm? The "edit configuration" seems to only support connecting somewhere instead of listening for incoming connections.
-
What exactly are you trying to achieve here..? – alessioalex Dec 09 '11 at 12:46
-
@alessioalex, set the breakpoint, read vars, and such - same as with remote xDebug - I'll set bp in PHPStorm, start listening, use putty to run the node script on the vm and it'll communicate with the IDE to let me do all the useful stuff – Fluffy Dec 09 '11 at 12:51
-
1Another option could be setting up SSH tunnel so that port open on local machine redirects to the port on the remote server. – CrazyCoder Dec 09 '11 at 13:24
2 Answers
Make sure you have the nodejs plugin installed.
If your server has the balancer package available (my EC2 box didn't), you can use this tutorial to forward the port with balancer.
yum install balance -yt
balance -df 8585 127.0.0.1.5858
Many report success with an iptables redirect from eth0 to lo (didn't work for me) like this:
iptables -t nat -A PREROUTING -p tcp -m tcp -i eth0 --dport 5858 -j DNAT --to 127.0.0.1:5858
There is also a simple node script described in this eclipse debugging tut (near the bottom), that will tunnel your local debug to a remote host.
But once I was that far down the path, I didn't see the point as I'm familiar with SSH. So ultimately, I went with an SSH tunnel and set up PHPStorm to debug localhost.

- 40,352
- 6
- 119
- 149
-
1It looks like PHPStorm just released a fix for [the bug with remote paths](http://youtrack.jetbrains.com/issue/WI-9821?projectKey=WI)! That should be very exciting. – Kato Apr 10 '12 at 17:21
-
do you still need to set a header when connecting from a browser as for PHP debug sessions? Also, Can you set breakpoints in the code within PHPStorm or do you need to do use sys.debug()? – codecowboy Nov 18 '15 at 11:03
For non-Windows users, here is how to setup the port forwarding tunnel using ssh:
ssh -f ssh_user@your-remote-host -L local_port:localhost:port_on_remote -N
This means "ssh to your-remote-host
, login as ssh_user
. Once there open connection to localhost:port_on_remote
and expose this connection at local_port
of machine where ssh is run".
The non-obvious piece is you need to use localhost
, since Node's debugger only binds itself to localhost ip address (and not to address to which your-remote-host
would resolve).
Example with real values:
ssh -f me@nodeserver.com -L 5858:localhost:5858 -N
(based on this howto, just took me some time to figure out the localhost
piece).

- 1,262
- 1
- 12
- 22