vscode nodejs remote debug RPi

Viewed 616

I am trying to set up VScode to debug a remote nodejs app on a Raspberry Pi 4. I use VScode - Insiders and the Remote Development extension with Remote - SSH (nightly). The SSH connection works perfectly fine and I can debug remote Python programs easily. When I launch a nodejs program (test.js) nothing happens. In the debug console I only see: /usr/bin/node test.js and then nothing happens. I can execute the same line in the VScode terminal and it runs as expected. My launch config is below, node debug is available on the remote. Can someone please help me out?

    {
        "name": "Launch Program",
        "program": "${workspaceFolder}/test.js",
        "request": "launch",
        "skipFiles": [
            "<node_internals>/**"
        ],
        "type": "node"
    },
1 Answers

In the following example your project will reside on your server in /path/to/my/project and your application will be called index.js.

On the server

Navigate to your project:

cd /path/to/my/project/

Run your application, activating the inspector by setting the --inspect parameter to the port you will tunnel into from your local system:

node --inspect=0.0.0.0:9229 ./index.js

On the local dev system

Set up an SSH tunnel to your server (replace username@remote.com with your user name and the address of your server):

ssh -L 9221:localhost:9229 username@remote.com

The server's port 9229 is now mapped to your localhost on port 9221.

In VS Code add the following configuration:

{
    "type": "node",
    "request": "attach",
    "name": "Debug remote",
    "protocol": "inspector",
    "address": "localhost",
    "port": 9221,
    "sourceMaps": true,
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/path/to/my/project/"
}

Set break points in your code and launch the "Debug remote" configuration in VS Code.

The code will now stop on your break points when you load a request in a browser.

Related