2021 Call for Code Awards: Live from New York, with SNL’s Colin Jost! Learn more

Develop a machine learning IoT app with Node-RED and TensorFlow.js


This code pattern shows how to build and deploy machine learning apps that can run offline and directly on a device (in this case a Raspberry Pi). Using Node-RED with TensorFlow.js, you can incorporate machine learning into your devices in an easy, low-code way.


In most cases, enabling your IoT device with AI capabilities involves sending the data from the device to a server. The machine learning calculations happen on the server and then the results are sent back to the device for appropriate action. However, this is not an ideal or feasible approach when data security or network connectivity is a concern.

By combining Node-RED with TensorFlow.js, you can more easily add machine learning functionality onto devices:

  • Node-RED is an open source visual programming tool that offers a browser-based flow editor for wiring together devices, APIs, and online services. Built on Node.js, you can extend the features of Node-RED by creating your own nodes or taking advantage of the JavaScript and NPM ecosystem.
  • TensorFlow.js is an open source JavaScript library to build, train, and run machine learning models in JavaScript environments such as the browser and Node.js.

When you have completed this code pattern, you will understand how to:

  • Create a Node-RED node that includes a TensorFlow.js model.
  • Build and deploy a Node-RED application that uses a TensorFlow.js node.


Node-RED and TensorFlow.js architecture flow diagram

  1. Use (or download) a machine learning model in TensorFlow.js format.
  2. Create a Node-RED node for the TensorFlow.js model and wire the TensorFlow.js node into a Node-RED application.
  3. Deploy the Node-RED application locally.
  4. Access the Node-RED application from a browser and trigger inferencing on images captured from a webcam.
  5. Alternatively, you can deploy the Node-RED application to a Raspberry Pi device.
  6. The device runs the Node-RED application and performs inferencing on images from a camera.
  7. The device outputs to a connected speaker or takes some other action depending on the inference results.


Go to the README file for detailed instructions on how to:

  1. Clone the repo.
  2. Install Node-RED.
  3. Install the TensorFlow.js node.
  4. Import the Node-RED flow.
  5. Deploy the Node-RED flow.