How to using environment variables in the subflow

I add a environment variables in the subflow. name is PinNumber and type is string. I have a Function node in this subflow. How to access PinNumber in the Function node ? :joy:

[{"id":"f89b2c94.be924","type":"func-exec","z":"aa6c467e.7329e","name":"cat gdix","func":"//var Pn = env.get(\"PinNumber\");\nvar exec = child_process.exec('cat /dev/gdi1', (error, stdout, stderr) => { \n if (error) { \n console.error(exec error: {error}`); \n return; \n } \n //console.log(`stdout: {stdout}); \n //console.log(stderr: ${stderr}); \n msg.payload = stdout.split('\\n').join('');\n callback(msg);\n}); ","outputs":1,"noerr":0,"x":382,"y":112,"wires":[[]]}]

Two things:

  • please read this How to share code or flow json and edit your code above accordingly so that other people can import it.

  • secondly the right way is var yourvar = env.get("yourvar");. But as the environment variables in subflows are quite recent additions and the func-exec node you use hasn’t been updated in 1 1/2 years it could be that it doesn’t support it. Is there a reason you don’t use a combination of a normal function node and an exec node instead?