Create your first flows

In this section, you’ll create your first flows in the Node-RED flow editor. An application in Node-RED is called a flow.

The palette in the left column shows you all the available nodes.

The nodes are grouped by category. The main categories of nodes are input, output, and function.

  • Use input nodes to input data into a Node-RED application, or flow.
  • Use output nodes to send data outside of a Node-RED flow.
  • Use function nodes to process data. You can use the function node to pass messages though a JavaScript function.

    1. Select an input inject node and drag it onto the canvas.

    1. Select an output debug node and drag it onto the canvas.

    1. Link, or wire, the two nodes together by clicking and dragging your cursor from one node to the other. Note that the debug and inject nodes change their display names when you drag them onto the canvas. This name change is expected and shows additional context for the node.

    1. Double-click the timestamp node. For the Payload field, select string.

    1. Enter a string, such as Hello, this is my first Node-RED application.
    2. In the Name field, enter a name for this node, such as Hello World inject.

    1. Click Done.

        1. The blue circles indicate that your flow has unsaved changes, which means that the application needs to be deployed.
        1. Click Deploy to deploy and save your changes.

          The debug node writes to the debug tab, which helps you monitor the flow through your application.

        2. To initiate the flow, click the tab linked to the inject node.

      You now see the output on the debug tab.

        1. In the filter nodes search field, enter translator to find the language translator node.

        1. Drag the node onto the canvas so that it lies in between the inject and debug nodes. You can move the nodes to make more space.

          To remove an unwanted line, select the line and press Delete on your keyboard.

        1. Double-click the language translator node. Select to translate from the inject English to another language. Select the Conversational domain.

        1. Click Done to save your changes.
        2. Select the language translator node and click the info tab.

      Notice that the node puts its translated output in msg.translation. msg is a reserved object that Node-RED uses to allow individual nodes to communicate with each other. Think of msg as an envelope into which one node places information that allows another node to read it. The language translator node is expecting to find a payload that is already in the msg envelope, and it will insert a translation into the msg envelope.

        1. Open the debug node and change the output to msg.translation. Enter the word translation after msg.

        1. Click Done to save your changes. Then, deploy your flow.
        2. Initiate the flow by clicking the tab on the inject node.

      View the translated text in the debug tab. The application is translating the text that you entered in the Payload field of the inject node.

        1. Modify the language translator node to use the News domain.

        1. Click Done and deploy your app.
        2. Initiate the flow and notice the difference in the translations for the different domains. For example, the difference between News and Conversation domains is the difference between how a newspaper might be translated and how a spoken conversation might be translated.

          Most of the time, there will be no difference, but occasionally certain terms and phrases are translated differently.

      You should now have a running instance of a Node-RED application on Bluemix with the Watson Language Translator and Conversation services, and you should be able to create basic flows.