How to Connect to Remote Debugger?

Yogesh Lakhotia
The Startup
Published in
2 min readJan 1, 2021
Connect debugger to remote server of your node application

Most of us do console.log to debug the code a remote server, which is very time consuming and takes multiple rounds to identify the bug.

I always prefer to debug code using debugger even in react-native because it saves time.

Just thought to share the process of connecting the debugger in a remote machine, so your all time can also be saved and of course attains bug solving happiness quicker 😛.

So what we need:
Pem file of the server or username and password through which we can enter the server.

Setup ssh port forwarding:

ssh username@remote-address -I "path/to/pem_file/ec2-server.pem" -L 8080:127.0.0.1:9230

Lets understand what command does:

-I is used for pem file
-L opens a local port. Everything that you send to that port is put through the ssh connection and leaves through the server.

Example: 8080:127.0.0.1:9230
8080[This is our local port]:127.0.0.1:9230[Server port]

Now we have to attach remote nodejs application debugger on port number 9230. So that it sends data to our local port 8080.

Most common process management tools exist for nodes is pm2. So sharing ecosystem.config.js file config.

Important line here is:

node_args : ["— inspect=127.0.0.1:9230"]

Start your node process:

pm2 start ecosystem.config.js

Now we will do config in our WebStorm to connect debugger.

Click on Run ➡ Edit Configuration

Click on + button and search for Attach to Node.js/Chrome

Next step is put the local port number. In our case its 8080 and click on Ok.

Run the debugger and we are done. Start putting break points in ide and happy debugging.

Miss Granger’s time turner can help us save time. Anyways, we don’t have that so let’s just use remote debugger. 🙃

--

--