Skip to Content

Create your own framework: Node-Red. First steps

This post, will be shown the first steps that must be taken into consideration in order to install and start working with Node-Red.
December 10, 2018 by
Create your own framework: Node-Red. First steps
Alejandro Jabalquinto

Introduction

This post, will be shown the first steps that must be taken into consideration in order to install and start working with Node-Red.

Requirements

Description

Node-red is a framework thought for an IoT solution. The framework is programmed using a graphical interface. In this post, we are going to focus on the first steps a user must know to start a node-red project.

Implementation

Run

node-red

Now you can go to http://localhost:1880 and start editing flows

Create a new node

https://nodered.org/docs/creating-nodes/first-node

Prepare the environment:

mkdir testNode
cd testNode/
npm init -y

edit package.json and add a “node-red” section:

"node-red": {
       "nodes": {
              "testNode": "testNode.js"
       }
}

edit testNode.js:

module.exports = function(RED) {
    function TestNode(config) {
       RED.nodes.createNode(this, config);
       var node = this;
       node.on("input",function(msg) {
           msg.payload = "test-node-value";
           node.send(msg);
       });
    }
    RED.nodes.registerType("testNode", TestNode);
}

edit testNode.html

<script type="text/javascript">
RED.nodes.registerType('testNode',{
category: 'function',
color: '#aa0099',
defaults: {
    name: {value:""}
},
inputs:1,
outputs:1,
label: function() {
return this.name || "test node";
}
});
</script>

<script type="text/x-red" data-template-name="testNode">
<div class="form-row">
         <label for="node-input-name"><i
class="icon-tag"></i> Name</label>
                 <input type="text" id="node-input-name"
placeholder="Name">
                        </div>
</script>

<script type="text/X-red" data-help-name="testNode">
<p>A simple node that converts the message payload to a test string</p>
</script>

Utility

Create a node template:

node-red-create-node <NodeName>

Deploy locally

sudo npm link
cd ~/.node-red/
npm link TestNode

Now you can edit it and use changes only restarting node-red.

Settings

https://nodered.org/docs/configuration

vi ~/.node-red/settings.js

uiPort number
httpAdminRoot false|path
disableEditor true|false
httpStatic path
adminAuth object
...

API

https://nodered.org/docs/creating-nodes/node-js

https://nodered.org/docs/user-guide/

​Search in our Blog

Create your own framework: Node-Red. First steps
Alejandro Jabalquinto December 10, 2018
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison