Create your own framework: Node-red. First steps

Create your own framework: Node-red. First steps

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. If you want to know the basics of Node-red you can go to this post:

An introduction to Node-Red

 

Installation

sudo npm install -g --unsafe-perm node-red

 

 Run

node-red

Now you can go to http://localhost:1880and 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);
       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',
    name: {vfalue:""}
    },
    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="lower-case">
    <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.json

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

 

API

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

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

 

Los comentarios están cerrados