Why is it worth exploring node.js development in an embedded environment? JavaScript is a widely known language that was designed to deal with user interaction in a browser.  Thanks to node.js, we can now use JavaScript outside of the browser, and even interact with hardware on devices such as the Raspberry Pi.

Here's a brief overview of some of the features that make node.js great for embedded development.

npm

npm is one of the best things to happen to node.js. npm is the package manager for node.  It makes managing third-party node dependencies a breeze, and makes it easy for mere mortals like myself to publish node.js packages.

Why is this important?  Community. Because npm is so great at managing dependencies, you can include open source libraries in your project hassle-free. Since it's easy to include community libraries, the community has grown exponentially, and the number of available packages is mesmerizing. Have you ever tried to install an Arduino library? No offense to Arduino, but it's not the most user friendly experience. Thankfully, they are working on adding a package manager to the Arduino IDE.

Events

Events are a great way to deal with user interaction.  What's an event?  Maybe it would be easiest to give you a few examples of events. Toggling a switch, clicking a mouse, and pressing a key on your keyboard are all examples of events.

The great thing about using event listeners is that you can write a chunk of code that will be called whenever an event happens. No longer do you have to constantly check the state of a button to see if the state has changed in a loop. Instead, the button will let you know when it was pressed! 

Streams

The node.js stream API combines the power of events, with the power of the Unix pipeline.  If you know how to pipe commands in Unix environments, you know it's a game changer. We'll dig deeper into streams after taking a look at how to setup the node.js environment on a Raspberry Pi.

This guide was first published on Dec 19, 2014. It was last updated on Mar 08, 2024.

This page (Why node.js?) was last updated on Dec 17, 2014.

Text editor powered by tinymce.