shaving
Allows manual triggering of flows
Can be scheduled to automatically inject at fixed intervals
Shows message content, either just payload or entire object in the debug sidebar
Runs user-defined js against the messages flowing past
Renders messages into a {{mustache}} template
Connects out, or listens for incoming connections
Define http endpoints for incoming requests, or trigger gets of urls in the middle of a flow
Publish and Subscribe nodes
Serial devices.
Raspberry Pi / BeagleBone Black GPIO pins
MongoDB, Redis, local files
Twitter, irc, email, xmpp
Uses vm.createScript under the covers to sandbox execution
console, util, Buffer included for convenience, but easy to add anything via settings
Returning messages>
return msg;
return [msg1, msg2, msg3];
return [msg1, [msgA, msgB] ];
Each function node has its own context object to save state between calls.
context.count = (context.count||0);
context.count += 1;
var countMessage = { payload: context.count };
return [msg, countMessage];
in settings.js
...
functionGlobalContext: {
arDrone: require('ar-drone')
}
...
then...
the first steps towards Node-RED-copter
context.client = context.client||context.global.arDrone.createClient();
if (msg.payload == "takeoff") {
context.client.takeoff();
} else if (msg.payload == "land") {
context.client.land();
}
.js : server-side behaviour
.html : appearance in editor & help
sentiment*:var sentiment = require('sentiment');
sentiment('Cats are stupid.',
function (err, result) {
console.dir(result); // Score: -2
}
);
sentiment('Cats are totally amazing!',
function (err, result) {
console.dir(result); // Score: 4
}
);
var RED = require("../../red/red");
var sentiment = require('sentiment');
function SentimentNode(n) {
RED.nodes.createNode(this,n);
this.on("input", function(msg) {
var node = this;
sentiment(msg.payload, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
});
}
RED.nodes.registerType("sentiment",SentimentNode);
<script type="text/javascript"> RED.nodes.registerType('sentiment',{ category: 'analysis-function', color:"#E6E0F8", defaults: { name: {value:""}, }, inputs:1, outputs:1, icon: "arrow-in.png", label: function() { return this.name||"sentiment"; }, labelStyle: function() { return this.name?"node_label_italic":""; } }); </script> <script type="text/x-red" data-template-name="sentiment"> <div class="form-row"> <label for="node-input-name"> Name </label> <input type="text" id="node-input-name"> </div> </script>
...
defaults: {
server: {value:"server",required:true},
port: {
value:"",
required: true,
validate: RED.validators.number()
},
host: {
value:"",
validate: function(v) {
return (this.server == "server")||v.length > 0;
}
}
}
...
...
oneditprepare: function() {
// called when the edit dialog is being built
},
oneditsave: function() {
// called when the edit dialog has been closed (not cancelled)
}
...
step 1 : add Eclipse Orion build files
<link rel="stylesheet" type="text/css" href="built-editor.css"/> <script src="built-editor.min.js"></script>
step 2 : initialise the editor when editing function node
oneditprepare: function() {
...
require(["orion/editor/edit"], function(edit) {
edit({
parent:document.getElementById('node-input-func-editor'),
lang:"js",
contents: $("#node-input-func").val()
});
...
}
[{"id": "3e4aa4b4.c1b55c", "type": "inject", "name": "", "topic": "", "payload": "Hello devWorks Days 2013", "repeat": "", "crontab": "", "once": false, "x": 98, "y": 174, "wires": [["b347e57e.4cb818"]]}, {"id": "b347e57e.4cb818", "type": "debug", "name": "", "active": true, "complete": false, "x": 358, "y": 211, "wires": []}]
Go get it: http://nodered.org
Just added to npm - work in progress
$ npm install node-red $ npm start node-red $ open http://localhost:1880
Online sharing of functions and flows - gist based
Allow individual nodes to be npm-installable
More Documentation (of course)