node-red icon indicating copy to clipboard operation
node-red copied to clipboard

getFlows is null

Open rudacs opened this issue 9 years ago • 4 comments

I'm trying to insert a node (config) into flow at runtime. I just tried it anyway. But always returns NULL.

I already put a setTimeout to see if it was not because it had not been created yet. But it does not work at all.

rudacs avatar Jun 16 '17 14:06 rudacs

Hi, can you be a bit more specific?

How have you initialised/started Node-RED prior to this point?

knolleary avatar Jun 16 '17 14:06 knolleary

var http = require('http');
var express = require("express");
var path = require('path');
var RED = require("node-red");

var app = express();
app.use("/",express.static("public"));
var server = http.createServer(app);

var settings = {
    httpAdminRoot:"/red",
    httpNodeRoot: "/api",
    userDir: path.join(__dirname, "nodered"),
    functionGlobalContext: { }    // enables global context
};
RED.init(server,settings);

app.use(settings.httpAdminRoot,RED.httpAdmin);
app.use(settings.httpNodeRoot,RED.httpNode);
server.listen(8000);

RED.start();

setTimeout(function() {
  var flows = RED.nodes.getFlows();
  console.log(flows); // return null
}, 5000);

rudacs avatar Jun 16 '17 14:06 rudacs

Hi, I have the same problem, When looking closely at RED.start() function... I found the starting process is asynchro

                redNodes.loadFlows().then(redNodes.startFlows); // <= We dont wait this promise is fullfil. 
                started = true;

I have created a PR, then we now can do something like:

RED.start().then(function() {
        var flows = RED.nodes.getFlows();
})

code2nguyen avatar Apr 23 '18 11:04 code2nguyen

Closing as part of a tidy-up of the issue tracker — this has been inactive for a long time and much has changed in Node-RED since. If it's still relevant on a current version, please open a fresh issue with up-to-date details and we'll take a look. Thanks for raising it.

knolleary avatar Jun 10 '26 13:06 knolleary