aalv
aalv

Reputation: 75

How to remotely live debug node.js app, while running on Azure App Service on Linux

I'm trying to remotely debug a node.js app while it is running on Azure App Service on Linux. VSCode's Azure Remote Debugging for Node.js is not working for me, so I'm trying remote debugging through a SSH session opened with Azure CLI's create-remote-connection command.

az webapp create-remote-connection –g [resource group] -n [app name] -p 9229

My launch.json file has

{
            "type": "node",
            "request": "attach",
            "name": "Attach to remote",
            "address": "127.0.0.1",
            "port": 9229,
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/home/site/wwwroot",

        }

Next, I run SSH on my machine with

ssh -L 9229:127.0.0.1:9229 [email protected]

but I don't know what to do next. How do I remotely live debug this app, while it is running on Azure App Service on Linux?

Upvotes: 1

Views: 797

Answers (1)

T. Webster
T. Webster

Reputation: 10109

Open a remote connection to your app using the az webapp remote-connection create command.

az webapp create-remote-connection –g [resource group] -n [app name]

The command output gives you the information you need to open an SSH session.

Verifying if app is running....
App is running. Trying to establish tunnel connection...
Opening tunnel on port: 49288
SSH is available { username: root, password: Docker! }

Initiate a local SSH tunnel, using the port from the output above.

ssh -L  9221:127.0.0.1:9229 [email protected] -p 49288

This starts a ssh tunnel session where a connection to port 9221 on your local machine will be forwarded to port 9229 on the remote container running in App Service.

Once authenticated, run the top command to get the pid of your node app. Let's say it's 67. Run node inspect.

node inspect -p 67

Run VSCode with the configuration in launch.json

{
            "type": "node",
            "request": "attach",
            "name": "Attach to remote",
            "address": "127.0.0.1",
            "port": 9221,
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/home/site/wwwroot",

        },

Upvotes: 1

Related Questions