# Building your first flow

Tekos flow and Node-RED share the same core, which allows you to wire together nodes to create flows which carry out your programming task. Messages pass between nodes, moving from input nodes through processing nodes to output nodes. Let’s take a brief look at nodes, flows and messages.

There are three main  types of nodes:

1. Input Nodes (e.g. inject)
2. Output Nodes (e.g. debug)
3. Processing Nodes (e.g. function)

<div align="left"><img src="https://2146957470-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSqSDdProPIpKBElfLq%2F-MRQ8ZnWLgz9fU9mWvx1%2F-MRQD4D92tFYEDU32qQR%2Fimage.png?alt=media&#x26;token=b5192ebc-c0f4-42ae-8ad6-306f9acabcc5" alt=""></div>

Input nodes allow you to input data into a Tekos-Flow application or “flow”. They have at least one output endpoint represented by the small grey square only on their right side. You use input nodes to connect data from other services, for example the  Twitter, Google, serial, websockets or tcp nodes, or to manually input data into a flow using the inject node.

Output nodes allow you to send data outside of a Tekos-Flow. They have a single input endpoint on their left side. You use output nodes to send data to other services, for example via Twitter, tcp, serial or email nodes, or to use the debug node to output to the debug pane.

Processing nodes allow you to process data. They have an input endpoint and one or more output endpoints. They allow you to transform the data type (e.g. json, csv, xml) nodes, use the data to trigger a message (e.g. trigger, delay) nodes and to write custom code that uses the data received (e.g. function node).

Note that some nodes, like the inject and debug messages, have a button that allows you to actuate a node (in the case of the inject node) or to enable and disable a node (in the case of the debug node).

Flows consist of multiple nodes wired together, with output tabs linked to input tabs of the next node in the flow. Messages flow along the nodes carrying data from node to node.

Tekos-Flow nodes consume input messages and produce output messages. Messages are JavaScript objects that contain at least a “payload” parameter, like this:

{% code title="Listing 2.1 A basic Tekos-Flow message structure" %}
```javascript
msg = {
  payload: "message payload"
};
```
{% endcode %}

Nodes consume and produce messages, usually using msg.payload as the main placeholder for the data they consume and produce. However, messages can be extended to contain other parameters. For example, to set the topic of a message and add a new parameter, location, you could create a new msg object as shown in listing 2.2.

```javascript
msg = {
  payload: "message payload",
  topic: "error",
  location: "somewhere in space and time"
};
```

Let’s use this knowledge to create your first flow.

## First flow

{% embed url="https://www.youtube.com/watch?v=46Ak61c_ymc" %}

To create a simple flow you start by dragging an injection node from the pallet to the workspace this node allows you manually inject messages into a flow, next add a debug node and wire them together by clicking on the inject nodes output and dragging on the debug node.

![](https://2146957470-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSqSDdProPIpKBElfLq%2F-MRQ8ZnWLgz9fU9mWvx1%2F-MRQEAlNfl_bzWEYI_GJ%2Fimage.png?alt=media\&token=bf079eb3-d4c5-42e9-bb85-741a09e03403)

With them wired together whenever the inject node sends a message it will be recived by te debug node, but at this point the flow only exist in the editor for it to starty doing anything it must be deployed to the runtime which you can do by clicking the deploy button in the header.&#x20;

![](https://tekos.co/wp-content/uploads/2020/10/Warstwa-2.png)

Once deployed you can click the button next to the inject node to trigger it, opening up the debug node sidebar shows the messages that arrive at the debug node. The default configuration of the inject node is to send the current timestamp formatted as milliseconds since January the first 1970. The default configuration of the debug node is to display the payload of each message.

![](https://tekos.co/wp-content/uploads/2020/10/debug.gif)

Next step is to add a function by dragging it from the palette and dropping it onto the wire between the existing nodes, this splices the node into the wire.

![](https://tekos.co/wp-content/uploads/2020/10/fucntionnode.gif)

The function node lets you write some JavaScript code that gets run against each message passing throught. To configure the node double-click on it to open it’s edit dialog, then start editing.

In this example we’ll change the code to reformat the inject nodes timestamp to a more human readable format.

![](https://tekos.co/wp-content/uploads/2020/10/fucntionnodeedit.gif)

&#x20;_Code:_

```javascript
msg.payload = new Date(msg.payload).toISOString();
return msg;
```

With that change made and deployed, now click the inject node and you can see the formatted message arrived in debug.

{% embed url="https://www.youtube.com/watch?v=_ST7fiBLlfw" %}
Also for easier workflow checkout tutorial about wiring nodes below.
{% endembed %}

