Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Remote Debugging Node on a Raspberry Pi

DZone's Guide to

Remote Debugging Node on a Raspberry Pi

Some practical advice on how to speed up Raspberry Pi development.

· IoT Zone
Free Resource

Address your IoT software testing needs – improve quality, security, safety, and compliance across the development lifecycle.

I 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 ran an 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 the figure below) I also made sure that Attach was selected in the debug dropdown on top.

Image title


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 an 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.

Accelerate the delivery of high-quality software in the connected IoT era through an integrated analysis, testing, security, and analytics platform

Topics:
debug ,raspberry pi ,node ,visual studio code

Published at DZone with permission of Daniel Egan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}