Remote Debugging Node on a Raspberry Pi

raspberry-logoI have been working on a project called Wackcoon (more on that later) that uses Node and runs on a Raspberry pi.  Like all development projects, I needed to debug not only my work but sometimes errors being thrown from node modules that I am using. Wrapping up my code in Try/Catch blocks and sending the error to console.log() got old really fast.  Since I could not test locally since I am running Linux on the raspberry pi,  I wanted to use Visual Studio Code to remote debug my project on the raspberry pi device itself.

The raspberry pi is on my network at home so on the pi I rand a ifconfig command to get the ip address of the device.

Then I went to Visual Studio Code and clicked on the debug icon (little bug in figure below)  I also made sure that Attach was selected in the debug dropdown on top.

debug1

Next I modified my launch.json file.  This is created the first time you run debug ( the green arrow ) .  In the launch.json file there are two sections.  One configuration is for launch ( debugging locally) and the other is for attaching to a already running process.  I put in the IP address that I got in the last step.

debug2

Now on the raspberry pi, I open a terminal and run the app using the –debug-brk option.  I can also just use the –debug option but the first one will have the application pause and wait for me on the first line of my code.

debug3

Now when I start my debug in Visual Studio Code (green arrow) you can see that it is sitting in break mode at line one.

debug4

I can set breakpoints, step in, step over, Step out, add watches, etc.. since this is being streamed from the pi, I cannot modify it on the fly like you can when you debug locally but still pretty cool.

Hope this helps

Daniel

 

 

One Comment
  1. Oscar

    Daniel,

    Very nice way to debug without much effort, at least for us the reader after you figured it out.
    Thanks

Comments are closed.