Calling node-red flows from node app

i found problem on embadding my node-red flow on my nodejs app.
here's my setting

// Create a server
var server_nr = http.createServer(app);

// Create the settings object - see default settings.js file for other options
var settings = {
httpNodeRoot: "/api",
functionGlobalContext: { } // enables global context

// Initialise the runtime with a server and settings

// Serve the editor UI from /red

// Serve the http nodes UI from /api

const port = process.env.PORT || 5000;

server = app.listen( port, function(){

// Launch the demo in the browser
opn("http://localhost:" + port +"/api/ui/#!/1" );
// Start the runtime


i always go this error app.min.js:148 ReferenceError: io is not defined
and a blank page.
any help please!!

well the error is unreadable ... so... hard to guess what it says...
but I'm going to start with the \ in your userDir path need to be escaped so \\ instead of \ or use / instead

no, none of them works .. is it a matter of port or server !!?

opn ? Is that some function you have defined ? (Don't forget this is running server side so won't open a browser)

const opn = require("opn");
Sorry but i don't really get your point. what's the problem with that !?

nothing apart from not being in the code you shared (I'm not a mind reader).
And also being a deprecated package...
carry on.

1 Like

The code you shared above does not include the require("opn") statement - so it was perfectly reasonable to question the opn(..) call.


That is not a valid value. This is meant to be the path the editor UI is served from. It must not have a # in it/