How to get the path of nodered folder

Hello all,
I would like to get the the path of where is running nodered, how I can do that ?
The current path of the folder is "/home/toto/.nodered". How I can get this path in the flow?
Thanks

msg.payload = `${os.homedir()}/.nodered`;

return msg;

That should work in a function node. may have to import os module in setup tab of function node

or just import this
[{"id":"feba76606996723c","type":"function","z":"9aee8eeac20f9015","name":"os.homedir()","func":"msg.payload = `${os.homedir()}/.nodered`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"os","module":"os"}],"x":1710,"y":840,"wires":[["e1a68d10b9905b8b"]],"info":"// nrlint function-eslint:off\n"}]

Thanks HaroldPetersInskipp,
That makes it

1 Like

Note though, that this is not a general solution. It will work if node red is installed in the conventional manner, but may not work if the install is not the conventional one. For example, I run multiple instances of node red on one machine, the folders it is configured in are /home/user/.node-red-1880, /home/user/.node-red-1881 etc. Also it does not work if node red is a Docker install.

Yeah, I had eventually run into that as well and my solution was to detect the OS first and then run a command in an exec node like this:

[{"id":"aafa49e090633de4","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"1b55b9fac53c0d3b","type":"exec","z":"aafa49e090633de4","command":"echo %cd%","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"pwd windows","x":610,"y":180,"wires":[["8066f1de239712fd"],[],[]]},{"id":"44c6f62fbc5fb7ed","type":"exec","z":"aafa49e090633de4","command":"pwd","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"pwd unix","x":600,"y":120,"wires":[["39efab045ccc5d11"],[],[]]},{"id":"546c70d79ade85c2","type":"function","z":"aafa49e090633de4","name":"check os","func":"msg.payload = msg.operatingSystem.name[0].toLowerCase();\nif (msg.payload === \"d\") {\n    node.send([{ \"payload\": \"\" }, null, null ]);\n} else if (msg.payload === \"l\") {\n    node.send([ null, { \"payload\": \"\" }, null ]);\n} else if (msg.payload === \"w\") {\n    node.send([ null, null, { \"payload\": \"\" }]);\n};","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":140,"wires":[["44c6f62fbc5fb7ed"],["44c6f62fbc5fb7ed"],["1b55b9fac53c0d3b"]],"outputLabels":["mac","linux","windows"]},{"id":"f92f05779dd953af","type":"function","z":"aafa49e090633de4","name":"os npm module","func":"// info about the current user\nmsg.user = os.userInfo();\n\n// returns the system uptime\nmsg.uptime = {\n    days: (os.uptime() / 86400).toFixed(2),\n    hours: (os.uptime() / 3600).toFixed(2),\n    minutes: (os.uptime() / 60).toFixed(2),\n    seconds: os.uptime().toFixed(2),\n};\n\n// info about the operating system\nmsg.operatingSystem = {\n    name: os.type(),\n    release: os.release(),\n    totalMem: `${parseFloat((os.totalmem() / Math.pow(1024, 3)).toFixed(2))}GB`,\n    freeMem: `${parseFloat((os.freemem() / Math.pow(1024, 3)).toFixed(2))}GB`,\n    architecture: os.arch(),\n    homeDir: os.homedir(),\n    tempDir: os.tmpdir(),\n    networkInt: os.networkInterfaces(),\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"os","module":"os"}],"x":260,"y":140,"wires":[["546c70d79ade85c2"]],"info":"// nrlint function-eslint:off\n"},{"id":"5d2100058e88d46a","type":"inject","z":"aafa49e090633de4","name":"run","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"","payloadType":"str","x":110,"y":140,"wires":[["f92f05779dd953af"]]},{"id":"8066f1de239712fd","type":"split","z":"aafa49e090633de4","name":"","splt":"\\","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":790,"y":180,"wires":[["91b6e330281f31b7"]]},{"id":"91b6e330281f31b7","type":"switch","z":"aafa49e090633de4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"index","v":"0","vt":"num","v2":"2","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":910,"y":180,"wires":[["fb71132b1f1fea39"]]},{"id":"fb71132b1f1fea39","type":"join","z":"aafa49e090633de4","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"/","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":180,"wires":[["39efab045ccc5d11"]]},{"id":"39efab045ccc5d11","type":"string","z":"aafa49e090633de4","name":"","methods":[{"name":"collapseWhitespace","params":[]},{"name":"ensureRight","params":[{"type":"str","value":"/.node-red"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":1170,"y":140,"wires":[["06171673b5b60ff7"]]},{"id":"06171673b5b60ff7","type":"debug","z":"aafa49e090633de4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1290,"y":140,"wires":[]}]

Similarly, pwd doesn't tell you where node red is running from (is where the flows file is). They could be different.

Maybe a search utility after determining OS? Unfortunately, I'm not familiar enough with the options available to get much further at that point.

I am pretty sure there is an api call to get the location of the flows file, though I don't know what it is.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.