Deploying and starting node-red flows from the command-line

3,034 views
Skip to first unread message

Professor Hantzen

unread,
Dec 5, 2016, 7:21:18 AM12/5/16
to Node-RED
Is this possible?

For example, if I had a flow file I wanted to run, I would ordinarily:

1) Enter "node-red" from the command line.
2) Navigate to localhost:1880 in a browser
3) Click "Deploy".
4) Click the "Start" button of the "Inject" node to commence the flow.

Conversely, if I'd developed in node.js, I would enter:

node <mynodefile.js>

On the command line to have my program up and running, and could package this in a shell script for example.

How can I achieve the same effect with node-red?  Is it possible to enclose the flows file in a node.js program for example?  Or is there a better way to achieve a similar outcome?

Many thanks!

Dave C-J

unread,
Dec 5, 2016, 8:01:37 AM12/5/16
to node...@googlegroups.com
by default node-red will start running the flows file as soon as you start it.
you can also pass in a flow file as a command line parameter if you like...
so 
    node-red  myflow.json
will run my file ... 

Ben Hardill

unread,
Dec 5, 2016, 11:14:42 AM12/5/16
to Node-RED
And inject nodes can be set to fire once on start

Dave C-J

unread,
Dec 5, 2016, 11:29:46 AM12/5/16
to node...@googlegroups.com

Good catch. Thanks Ben

Professor Hantzen

unread,
Dec 5, 2016, 11:34:51 AM12/5/16
to Node-RED
Oh! Lol - that's somewhat easier than I thought it'd be. :D  I didn't realise you could specify a specific flow file, and totally forgot about "Inject once on start" - of course! Thank you both.

Out of interest, is there a way to package a flow in a node.js file?  Eg, if I wanted to implement a flow into some code I already have.

Julian Knight

unread,
Dec 5, 2016, 11:55:16 AM12/5/16
to Node-RED
As NR runs in its own process, you could simply spawn it. Capture the PID so you can terminate it and monitor it too - Node.JS is ACE!
Reply all
Reply to author
Forward
0 new messages