Programatically Get Node Red Version Number

397 views
Skip to first unread message

Ben Ward

unread,
Apr 27, 2015, 3:47:44 PM4/27/15
to node...@googlegroups.com
My search skills have failed me.

How do I programatically retrieve the version number of node-red to stick in a variable? I have used exec to get the node version, but can't find the node-red version, except by starting red.js

I see something in ~/.node-red/.config.json but I can't work out how to access this data.

Thanks
Ben

--
b...@love-hz.com | http://love-hz.com | skype: badgercrouch | Twitter:@welovehz

Nicholas O'Leary

unread,
Apr 27, 2015, 4:04:45 PM4/27/15
to Node-RED Mailing LIst
Hi Ben,

in what language are you doing this?  You want the version field from node-red/package.json 

Nick



--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Ward

unread,
Apr 27, 2015, 4:14:17 PM4/27/15
to node...@googlegroups.com
Hi Nick,

I'm doing this from a node-red function node.

Would I use a file node to get that?

Thanks
Ben


--
b...@love-hz.com | http://love-hz.com | skype: badgercrouch | Twitter:@welovehz

Ben Ward

unread,
Apr 28, 2015, 5:29:54 AM4/28/15
to node...@googlegroups.com
Just to follow up on this, it was surprisingly easy once I had the hint.

What I did was 
  1. create a file node which accesses /usr/local/lib/node_modules/node-red/package.json attached to the startup trigger.
  2. The output is then passed through a json node 
  3. then a function node has access to the version number as msg.payload.version which I stash in a context object 
  4. I use the collected values at startup to send as json over MQTT to report on the device's status/health/uptime/version/ip/mac/subdevices etc to the broker.
Inline images 1
Code below.

Thanks for the help, Nick

Ben

[{"id":"347f0afc.cb80f6","type":"file in","name":"Package file","filename":"/usr/local/lib/node_modules/node-red/package.json","format":"utf8","x":453,"y":303,"z":"3feb2ac7.c014d6","wires":[["216d0ef2.de92f2"]]},{"id":"216d0ef2.de92f2","type":"json","name":"","x":610,"y":305,"z":"3feb2ac7.c014d6","wires":[["4d59a194.b2a66"]]},{"id":"4d59a194.b2a66","type":"function","name":"Export Nodered version","func":"// Add node red  version number to device object\ncontext.global.noderedversion = msg.payload.version;\n\nreturn msg;","outputs":1,"valid":true,"x":810,"y":299,"z":"3feb2ac7.c014d6","wires":[[]]}]







--
Director, Love Hz | 07771 537574 
b...@love-hz.com | http://love-hz.com | skype: badgercrouch | Twitter:@welovehz

Nicholas O'Leary

unread,
Apr 28, 2015, 5:31:20 AM4/28/15
to Node-RED Mailing LIst
Ah well done Ben... this was next on my list to reply to, so glad to hear you figured it out.

N

Julian Knight

unread,
Apr 28, 2015, 11:52:35 AM4/28/15
to node...@googlegroups.com
Interesting, thanks for sharing Ben.

I approached some of this slightly differently as I prefer to run NR as an embedded app. So I populate context.global via the server.js startup script where I pass through a number of settings such as the service IP address (both internal and external), the ports in use, the addresses and ports for MQTT and a couple of references to Node.js libraries like fs and lodash that I'm likely to use across quite a few function nodes.


On Tuesday, 28 April 2015 10:31:20 UTC+1, Nicholas O'Leary wrote:
Ah well done Ben... this was next on my list to reply to, so glad to hear you figured it out.

N
On 28 April 2015 at 10:29, Ben Ward <b...@love-hz.com> wrote:
Just to follow up on this, it was surprisingly easy once I had the hint.

What I did was 

Reply all
Reply to author
Forward
0 new messages