Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote debugging in Visual Studio Code

I have a node.js application hosted in AWS EC2 instance. I ssh into the host with .pem file for authentication. Is there any way I could debug this code in VS Code, I see there is remote debugging in VS Code, there is configuration to specify port and host but no option to specify the pem file.

How should I configure VS code to debug?

like image 696
vikneshwar Avatar asked Jan 18 '26 15:01

vikneshwar


2 Answers

I was also facing same issue the solution is very simple, bind your inspector to 0.0.0.0 instead of 127.0.0.1

so change your package.json script to something like this:

scripts:{
 "debug": node --inspect=0.0.0.0:9229 ./bin/www
 ...
}

Reference: https://medium.com/@auchenberg/introducing-remote-debugging-of-node-js-apps-on-azure-app-service-from-vs-code-in-public-preview-9b8d83a6e1f0

like image 75
vats Avatar answered Jan 21 '26 05:01

vats


According to the VS Code documentation on remote debugging Node, you need to specify a TCP/IP address and port number for the EC2 instance. These are set in the address attribute of the launch.json file in your workspace's .vscode folder.

Here is an example:

{
    "type": "node",
    "request": "attach",
    "name": "Attach to remote",
    "address": "TCP/IP address of process to be debugged",
    "port": "9229"
}

Make sure the port (9229 in this example) is included in the rules in your security groups to allow in traffic for this port. Here is an overview of rules and security groups for Linux instances if you need to review this.

like image 32
Taterhead Avatar answered Jan 21 '26 05:01

Taterhead



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!