How to remote debug Node JS with PHPStorm?

后端 未结 2 1779
鱼传尺愫
鱼传尺愫 2021-02-06 01:38

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\

2条回答
  •  我在风中等你
    2021-02-06 02:36

    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).

提交回复
热议问题