Belajar Node Red

3 min read 7 days ago
Published on Aug 25, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial is designed to guide you through the basics of Node-RED, a visual programming tool used for connecting hardware devices, APIs, and online services in IoT applications. Whether you are a beginner or looking to refresh your skills, this step-by-step guide will help you understand Node-RED's functionality and how to get started.

Step 1: Install Node-RED

  1. Prerequisites: Ensure you have Node.js installed on your machine. You can download it from Node.js official site.
  2. Install Node-RED:
    • Open your terminal or command prompt.
    • Run the following command to install Node-RED globally:
      npm install -g node-red
      
  3. Start Node-RED:
    • After installation, start Node-RED by typing:
      node-red
      
    • This will launch Node-RED, typically accessible at http://localhost:1880.

Step 2: Navigate the Node-RED Interface

  1. Overview of the Interface:

    • You will see the main workspace where you can drag and drop nodes.
    • The palette on the left contains different nodes categorized by functionality.
    • The sidebar allows you to configure nodes and view debug messages.
  2. Familiarize Yourself with Node Types:

    • Input Nodes: Receive data from various sources (e.g., HTTP, MQTT).
    • Output Nodes: Send data to destinations (e.g., Dashboard, devices).
    • Function Nodes: Allow you to write custom JavaScript code to manipulate data.

Step 3: Create Your First Flow

  1. Add Nodes:

    • Drag an input node (like an Inject node) onto the workspace.
    • Drag an output node (like a Debug node) next to it.
  2. Connect Nodes:

    • Click on the small circle on the right side of the Inject node and drag it to the left side of the Debug node to create a link.
  3. Configure the Inject Node:

    • Double-click the Inject node to configure it.
    • Set the payload type (e.g., string, number) and value.
  4. Deploy the Flow:

    • Click the Deploy button in the top right corner to save your changes.
  5. Test the Flow:

    • Click the button on the Inject node to trigger it.
    • Check the debug tab on the right sidebar to see the output.

Step 4: Expand Your Flow with Additional Functionality

  1. Add More Nodes:

    • Explore various nodes from the palette, such as Function nodes for data processing or HTTP Request nodes for API calls.
  2. Use Function Nodes:

    • Drag a Function node to the workspace and connect it between an input and output node.
    • Double-click to edit and write JavaScript code for custom data manipulation. For example:
      msg.payload = msg.payload.toUpperCase();
      return msg;
      
  3. Deploy and Test:

    • After making changes, click Deploy again.
    • Test the flow by injecting data and observing how it processes through the function node.

Step 5: Create a Dashboard

  1. Install Dashboard Nodes:

    • In the terminal, install the dashboard package:
      npm install node-red-dashboard
      
  2. Add Dashboard Nodes:

    • Drag dashboard nodes (e.g., ui_button, ui_gauge) from the palette.
    • Connect them to your flow as needed.
  3. Access the Dashboard:

    • Once deployed, access your dashboard at http://localhost:1880/ui.

Conclusion

You've now learned the basics of Node-RED, from installation to creating your first flow and building a simple dashboard. Node-RED is powerful for building IoT applications, and with this foundation, you can explore more complex interactions and integrations.

Next steps can include:

  • Experimenting with different node types.
  • Integrating external APIs.
  • Exploring community contributions and shared flows on the Node-RED website.

Happy coding!