Remote Debugging Node on a Raspberry Pi
Some practical advice on how to speed up Raspberry Pi development.
Join the DZone community and get the full member experience.Join For Free
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
blocks and sending the error to
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
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
was selected in the debug dropdown on top.
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.
now on the raspberry pi, i open a terminal and run the app using the
option. i can also just use the
option but the first one will have the application pause and wait for me on the first line of my code.
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.
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.
Published at DZone with permission of Daniel Egan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.