Open up the Internet of things with Node-red

How do you even begin to wrap your head around developing applications for the Internet of things? For Node.js devs, Node-red provides a useful visual development environment

The Internet of things promises much, with connected devices instrumenting and actuating the world. But it’s not easy to build code for, with different classes of devices needing different application frameworks -- and with tooling that’s often primitive when compared to modern IDEs.

Developed by IBM and open-sourced, Node-red is an interesting alternative to traditional development techniques. Designed to link Node.js instances to the Internet of things, it’s perhaps best thought of as a visual programming tool that runs on top of Node.js, allowing developers to build and manage information flows quickly.

The heart of Node-red is the concept of the flow, tracing the path information takes from input to output. It’s a conceptual model that makes a lot of sense when considering how code needs to interact with both Web services and with devices. While you can build complete applications in Node-red, it’s more a tool for transforming inputs and pushing them to outputs, much like the devices it’s working with.

Installation is quick and easy, building on an existing Node.js install. Node-red installs as an NPM module, up and running in mere minutes, ready for you to start coding. You can choose from a library of modules to add to your install, including specific tooling for key Internet of things platforms. It treats some, like Arduino, as serial connections, while more-capable platforms can host Node.js and Node-red directly.

Writing code in Node-red is a lot easier than working with raw Node.js. Once Node-red is installed and running, you use a browser to work with the Node-red development tools. Connect to localhost on your development system, and you’re presented with a visual development surface that’s reminiscent of the MIT Media Brick-inspired Lego Mindstorms robotics toolkit or Microsoft’s Robotics Development Studio.


Node-red is a visual programming tool that allows developers to build and manage information flows for the Internet of things.

A panel on one side shows a list of available modules (unsurprisingly called nodes), and on the right a debugging view shows information from the currently selected node. In the middle is a work area where you drag and drop nodes and wire them together, clicking to customize the information they deliver and to add more functions with JavaScript.

Comparing Node-red with Lego Mindstorms makes sense. Both tools abstract programming away from the underlying compute hardware using basic building blocks to get you started -- then let you customize the resulting code by adding scripts to functional blocks. It’s a logical approach to the Internet of things, where what’s important is handling the flow of information between devices and the software used to manage inputs and outputs.

Out the box, Node-red gives you a mix of basic input nodes that can be dragged from the toolbar onto the development surface. It’s worth following the tutorials on the Node-red site, as they introduce key concepts that aren’t obvious at first sight. One important idea is the use of timers as triggers for actions.

Node-red provides an inject node that’s used to deliver timestamps, which can also be configured to trigger actions at set times -- for example, grabbing the output from an API every five minutes. It’s a useful technique for working with sensors and sampling data when you want it, rather than overloading systems with redundant data. Node-red is at heart an asynchronous programming model, so timed triggers can help you control program flow.

Using a trigger like this to control your application, you can quickly build a Node-red flow that chains various nodes together, processing and formatting information before delivering it to appropriate outputs. It’s easy to see how sensor input can be processed and delivered to a Web page or to a waiting cloud API. Similarly, content from the Web can be output using hardware, delivering information in new and innovative ways -- surfacing information using LED cubes, say, or other ambient indicators.

The key to working with Node-red is understanding how information flows between program nodes. Each node delivers message payloads, which can then be acted on by other nodes. Once you’ve dropped a node onto the Node-red development surface, you’ll drag connections to the nodes that will work with its output. Code is best thought of as a filter, modifying the input and delivering it to an output -- either formatting it or processing it.

While Node-red runs well on standard PCs and servers, there’s also the option of installing it on smaller devices, with versions for both Raspberry Pi and the BeagleBone developer boards. If you’re using Node-red on a Pi, you can add a module that gives direct access to its GPIO pins, as well as tools for using the familiar Arduino Wiring language to work with the Pi’s I/O ports. Node-red and Raspberry Pi work well together, especially on the newer, more powerful, Pi 2 hardware -- and the combination makes a useful prototyping platform for building smart nodes that link sensors and the wider Internet, with basic signal processing before handing off data to cloud services.

IBM’s work on Node-red has opened up developing device applications to a wider audience, with a simple set of application development tools. While you’re unlikely to use Node-red to build and run production services, it’s certainly a useful tool for prototyping Internet of things applications. It’s easy to use it to connect a wide range of developer boards to the Internet and to wire up simple applications that can be used as a proof of concept.

While you’re likely to write much lower-level code for your production tools and services, Node-red’s visual approach to service design makes it easier to take your ideas and turn them into working code. It’s not only a tool for working with device-side code, and that gives you the option of scaling Node-red-based applications by integrating them with message queues and with Node.js microservice frameworks.

Copyright © 2015 IDG Communications, Inc.