Remotely debugging my node app that is hosted on AWS

前端 未结 7 491
别那么骄傲
别那么骄傲 2021-01-29 21:10

I would like to connect to my node server running in debug mode on AWS (node --debug app.js) from my development machine, and be able to debug my app remotely.

Two quest

相关标签:
7条回答
  • 2021-01-29 21:17

    One more option to use 0.0.0.0 to listen to request from outside:

    node-debug --web-host=0.0.0.0 --cli app.js
    

    and visit this address to debug:

    http://<the-domain>:8080/?port=5858
    

    it would be better if HTTP/2 is available since there are lots of small files.

    0 讨论(0)
  • 2021-01-29 21:22

    Allow me to present an alternative using node --inspect. I had the same need, although in a Windows environment, I believe this should work for you.

    Remote machine (tested with Node 6.10.2, Windows Server 2012)

    node --inspect=0.0.0.0:9229 <appname>.js

    Local Machine (tested with Win 10, Chrome 60.0.3112.90)

    In Chrome DevTools - Click the vertical ellipsis menu in top right:

    1. Go to: More Tools -> Remote Devices
    2. Under Network targets Click Add address
    3. Enter <remote-ip>:9229
    4. Once you enter address and remote target is connected you'll see Node.JS Icon on Top Left of DevTools
    5. Click NodeJS Logo to launch DevTools Node Debugger

    Screenshots of Steps 1,3,4 below.

    0 讨论(0)
  • 2021-01-29 21:23

    This is what worked for me:

    1. Start node-inspector on server.
    2. Start debugee on remote server with --debug flag.
    3. Note the port that the debugger listens on, i.e. Debugger listening on port DEBUG_PORT message.
    4. Create an ssh tunnel for port 8080, not the DEBUG_PORT as Andrey Sidorov's answer suggests.
    5. Open SERVER_API:8080/debug?ws=127.0.0.1:8080&port=DEBUG_PORT in browser an voilà.

    Node Inspector v0.10.1

    0 讨论(0)
  • 2021-01-29 21:27

    And with the help of tepez's answer, the following worked for me (Node Inspector v0.12.2):

    On my machine:

    ssh -L 8080:127.0.0.1:8080 <username>@<host> -N
    

    On the remote server:

    node-debug --cli <appname>
    

    And enter the following address in the browser:

    127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858
    
    0 讨论(0)
  • 2021-01-29 21:31

    Forward remote debugger port with ssh from your dev machine

    ssh -L 5858:127.0.0.1:5858 ubuntu@some.ec2.host.com
    

    And now you can start node-inspector as if the debugger is running locally.

    0 讨论(0)
  • 2021-01-29 21:31

    You can use node --inspect too in your remote machine.

    1. Start your node with node --inspect myapp.js
    2. Then locally ssh -L 9229:127.0.0.1:9229 myuser@myserver -N
    3. Search for an string like this at the log head and copy it chrome-devtools://devtools/remote/serve_file/@60cd6e859b9ff284980/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/bef2ae68
    4. Paste it in your chrome browser

    Enjoy :)

    If you are using pm2 just add this on your ecosystem.js

    "apps": [{
        "name": "myapp",
        "script": "index.js",
        "node_args": ["--inspect"],
    ...
    
    0 讨论(0)
提交回复
热议问题