Connecting WebStorm to a remote node.js debugging session

后端 未结 4 677
梦毁少年i
梦毁少年i 2020-12-14 17:35

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

相关标签:
4条回答
  • 2020-12-14 18:15

    This is what I do in my linux Debian VM:

    install balancer

    sudo apt-get install balance -y

    create a route in balancer to reroute your 5858 port to 5859

    balance 5859 127.0.0.1:5858

    start your app

    node --debug app.js

    now you can access it from outside the VM on port 5859

    0 讨论(0)
  • 2020-12-14 18:19

    1) From WebStorm manual:

    When the application to debug is running on a physically remote host, you need to run a proxy or any other software that ensure port forwarding on the Node.js server. This is necessary because the debug port can open only on the localhost network interface. The localhost network interface cannot be accessed from another machine therefore WebStorm cannot connect to it upon initiating a debugging session.

    2) localhost on VM is not the same localhost (as strange as it sounds) on host.

    3) V8 debugger is listening on localhost

    Solution:

    You can setup ssh proxy to linux VM: ssh -L 5858:127.0.0.1:5858 <vm_user>@<vm_ip> -N and here you can find answer how to do it on Windows -> stackoverflow If you will do the above your debug configuration in WebStorm will be Host: 127.0.0.1 Port: 5858

    You can check if WebStorm is connected to remote debug session by checking Debugger tab and Variables panel. can not connect, connected

    0 讨论(0)
  • 2020-12-14 18:25

    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.

    0 讨论(0)
  • 2020-12-14 18:31

    Just a heads up, when I tried this I had to use --debug-brk. Running with just --debug didn't allow WebStorm to set breakpoints after connecting.

    0 讨论(0)
提交回复
热议问题