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.
-
- Select an input inject node and drag it onto the canvas.
-
- Select an output debug node and drag it onto the canvas.
-
- 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.
-
- Double-click the timestamp node. For the Payload field, select string.
-
- Enter a string, such as
Hello, this is my first Node-RED application
. - In the Name field, enter a name for this node, such as
Hello World inject
.
- Enter a string, such as
-
- Click Done.
-
- The blue circles indicate that your flow has unsaved changes, which means that the application needs to be deployed.
-
- 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.
- To initiate the flow, click the tab linked to the inject node.
- Click Deploy to deploy and save your changes.
You now see the output on the debug tab.
-
- In the filter nodes search field, enter
translator
to find the language translator node.
- In the filter nodes search field, enter
-
- 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.
- 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.
-
- Double-click the language translator node. Select to translate from the inject English to another language. Select the Conversational domain.
-
- Click Done to save your changes.
- 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.
-
- Open the debug node and change the output to
msg.translation
. Enter the wordtranslation
aftermsg
.
- Open the debug node and change the output to
-
- Click Done to save your changes. Then, deploy your flow.
- 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.
-
- Modify the language translator node to use the News domain.
-
- Click Done and deploy your app.
- 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.