getFlows is null
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.
Hi, can you be a bit more specific?
How have you initialised/started Node-RED prior to this point?
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);
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();
})
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.