How to use node-red - 10 common examples

To help you get started, we’ve selected a few node-red examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BiancoRoyal / node-red-contrib-modbus / src / testing / nodered-helper.js View on Github external
return defer.promise
      },
      saveCredentials: function () {
                // do nothing
      }
    }
    var settings = {
      available: function () {
        return false
      }
    }

    var red = {}
    for (var i in RED) {
      if (RED.hasOwnProperty(i) && !/^(init|start|stop)$/.test(i)) {
        var propDescriptor = Object.getOwnPropertyDescriptor(RED, i)
        Object.defineProperty(red, i, propDescriptor)
      }
    }

    red['_'] = function (messageId) {
      return messageId
    }

    redNodes.init({settings: settings, storage: storage, log: log})
    credentials.init(storage, express())
    RED.nodes.registerType('helper', helperNode)

    if (Array.isArray(testNode)) {
      for (var n = 0; n < testNode.length; n++) {
        testNode[n](red)
      }
github BiancoRoyal / node-red-contrib-modbus / src / testing / nodered-helper.js View on Github external
defer.resolve(testCredentials)
        return defer.promise
      },
      saveCredentials: function () {
                // do nothing
      }
    }
    var settings = {
      available: function () {
        return false
      }
    }

    var red = {}
    for (var i in RED) {
      if (RED.hasOwnProperty(i) && !/^(init|start|stop)$/.test(i)) {
        var propDescriptor = Object.getOwnPropertyDescriptor(RED, i)
        Object.defineProperty(red, i, propDescriptor)
      }
    }

    red['_'] = function (messageId) {
      return messageId
    }

    redNodes.init({settings: settings, storage: storage, log: log})
    credentials.init(storage, express())
    RED.nodes.registerType('helper', helperNode)

    if (Array.isArray(testNode)) {
      for (var n = 0; n < testNode.length; n++) {
        testNode[n](red)
github BiancoRoyal / node-red-contrib-modbus / src / testing / nodered-helper.js View on Github external
startServer: function (done) {
    server = http.createServer(function (req, res) {
      app(req, res)
    })
    RED.init(server, {
      SKIP_BUILD_CHECK: true,
      logging: {console: {level: 'off'}}
    })
    server.listen(listenPort, address)
    server.on('listening', function () {
      port = server.address().port
      url = 'http://' + address + ':' + port
      comms.start()
      done()
    })
  },
    // TODO consider saving TCP handshake/server reinit on start/stop/start sequences
github aspnet / Wave / app.js View on Github external
verbose: false,
    flowFile: path.join(basedir, 'flows_Dispatcher.json'),
    mqtt_dynamic:
    {
        broker: config.broker.host,
        broker_port: (config.broker.port ? config.broker.port : 1883),
        broker_username: config.broker.username,
        broker_password: config.broker.password,
        clientid: config.clientid,
        clientconfig: objUtil.extend(clientconfig, { "status": "online" }),
        clientconfig_offline: objUtil.extend(clientconfig, { "status": "offline" })
    }
};

// Initialise the runtime with a server and settings
RED.init(server, settings);

// Serve the editor UI from /red
app.use(settings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot, RED.httpNode);

server.listen(8000);

// Start the runtime
RED.start();

console.log("=================================================");
console.log("Flows Dir      : " + path.resolve(settings.userDir));
console.log("Node-Red Url   : http://localhost:8000/red/");
console.log("=================================================");
github sakazuki / aws-serverless-node-red / lambda.js View on Github external
let init = (() => {
  if (headless) {
    RED.init(settings)
  }else{
    RED.init(server, settings)
    //app.use(settings.httpAdminRoot,RED.httpAdmin);
    app.use(settings.httpNodeRoot,RED.httpNode);
  }
  return new Promise((resolve, reject) => {
    let deployed;
    RED.events.on("runtime-event", deployed = function(data){
      if (data.id === "runtime-deploy") {
        RED.events.removeListener("runtime-event", deployed);
        // console.log('flow deployed');
        resolve();
      }
    })
    RED.start();
  });
github TotallyInformation / node-red-template-embedded / server.js View on Github external
// Create the http(s) server
if (use_https) {
  var privateKey = fs.readFileSync("server.key", "utf8");
  var certificate = fs.readFileSync("server.crt", "utf8");
  var credentials = {
    key: privateKey,
    cert: certificate
  };
}
var httpServer = use_https
  ? http.createServer(credentials, app)
  : http.createServer(app);

// Initialise the runtime with a server and settings
// @see http://nodered.org/docs/configuration.html
RED.init(httpServer, nrSettings);

// Serve the editor UI from /admin
app.use(nrSettings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes from /
app.use(nrSettings.httpNodeRoot, RED.httpNode);

httpServer.listen(http_port, listening_address, function() {
  console.info(
    "Express 4 https server listening on http%s://%s:%d%s, serving node-red",
    use_https ? "s" : "",
    httpServer.address().address.replace("0.0.0.0", "localhost"),
    httpServer.address().port,
    nrSettings.httpAdminRoot
  );
});
github ibm-watson-iot / iot-nodejs / samples / oldstuff / cognitive / app.js View on Github external
console.log('VCAP_SERVICES: %s', process.env.VCAP_SERVICES);
    // Also parse Cloudant settings.
    var couchService = env['cloudantNoSQLDB'][0]['credentials'];
}

if (!couchService) {
    console.log("Failed to find Cloudant service");
    if (process.env.NODE_RED_STORAGE_NAME) {
        console.log(" - using NODE_RED_STORAGE_NAME environment variable: "+process.env.NODE_RED_STORAGE_NAME);
    }
    throw new Error("No cloudant service found");
}
settings.couchUrl = couchService.url;

// Initialise the runtime with a server and settings
RED.init( httpServer, settings );

// Serve the editor UI from /red
app.use( settings.httpAdminRoot, RED.httpAdmin );

// Serve the http nodes UI from /api
app.use( settings.httpNodeRoot, RED.httpNode );

httpServer.listen( port, function(){
    console.log('App listening on port: ', port);
});

// Start the runtime
RED.start();
github EdgeVerve / loopback-connector-nodes-for-Node-RED / node-red.js View on Github external
nodesDir : '../nodes',
            flowFile : 'node-red-flows.json',
            functionGlobalContext : {}
        // enables global context
        };
    }
    
    // Initialise the runtime with a server and settings
    RED.init(server, settings);
    // Serve the editor UI from /red
    app.use(settings.httpAdminRoot, RED.httpAdmin);
    
    // Serve the http nodes UI from /api
    app.use(settings.httpNodeRoot, RED.httpNode);
    var adminApp = RED.httpAdmin;
    var redNodes = RED.nodes;
    
    if (!options.settings.server) {
        
        var port = options ? options.port || 3001 : 3001;
        server.listen(port);
        RED.start().then(function () {
            return callback();
        });
    }
    else {
        // Start the runtime - removing earlier timeout implementation!!
        RED.start().then(function () {
            return callback();
        }).otherwise(function (err) {
            console.log('**ERROR : NODE RED WAS NOT STARTED ***' , err);
        });
github TotallyInformation / node-red-template-embedded / server.js View on Github external
var certificate = fs.readFileSync("server.crt", "utf8");
  var credentials = {
    key: privateKey,
    cert: certificate
  };
}
var httpServer = use_https
  ? http.createServer(credentials, app)
  : http.createServer(app);

// Initialise the runtime with a server and settings
// @see http://nodered.org/docs/configuration.html
RED.init(httpServer, nrSettings);

// Serve the editor UI from /admin
app.use(nrSettings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes from /
app.use(nrSettings.httpNodeRoot, RED.httpNode);

httpServer.listen(http_port, listening_address, function() {
  console.info(
    "Express 4 https server listening on http%s://%s:%d%s, serving node-red",
    use_https ? "s" : "",
    httpServer.address().address.replace("0.0.0.0", "localhost"),
    httpServer.address().port,
    nrSettings.httpAdminRoot
  );
});

// Start the runtime
RED.start();
github EdgeVerve / loopback-connector-nodes-for-Node-RED / node-red.js View on Github external
userDir : 'nodered/',
            nodesDir : '../nodes',
            flowFile : 'node-red-flows.json',
            functionGlobalContext : {}
        // enables global context
        };
    }
    
    // Initialise the runtime with a server and settings
    RED.init(server, settings);
    // Serve the editor UI from /red
    app.use(settings.httpAdminRoot, RED.httpAdmin);
    
    // Serve the http nodes UI from /api
    app.use(settings.httpNodeRoot, RED.httpNode);
    var adminApp = RED.httpAdmin;
    var redNodes = RED.nodes;
    
    if (!options.settings.server) {
        
        var port = options ? options.port || 3001 : 3001;
        server.listen(port);
        RED.start().then(function () {
            return callback();
        });
    }
    else {
        // Start the runtime - removing earlier timeout implementation!!
        RED.start().then(function () {
            return callback();
        }).otherwise(function (err) {
            console.log('**ERROR : NODE RED WAS NOT STARTED ***' , err);