[{"data":1,"prerenderedAt":205},["ShallowReactive",2],{"blog-\u002Fblog\u002F2023\u002F01\u002Fenvironment-variables-in-node-red":3},{"id":4,"title":5,"body":6,"description":12,"extension":194,"meta":195,"navigation":200,"path":201,"seo":202,"stem":203,"__hash__":204},"blog\u002Fblog\u002F2023\u002F01\u002Fenvironment-variables-in-node-red.md","Using Environment Variables in Node-RED",{"type":7,"value":8,"toc":184},"minimark",[9,13,25,40,47,68,77,82,95,111,115,118,125,130,133,140,144],[10,11,12],"p",{},"Programs, written with Node-RED or otherwise, need to sometimes retrieve information that wasn’t decided on during the creation of the program.",[10,14,15,16,20,21,24],{},"Contextual data like configuration, which user is executing the code, differentiate based on what device is executing a flow, or sometimes secrets which shouldn’t be exposed in the code. This is usually done through environment variables. These are pairs of strings, a key with an attached value, which are accessed by their key. Say you want to access an API endpoint with a key, you’d save the key as ",[17,18,19],"code",{},"API_KEY"," with the value set to ",[17,22,23],{},"yoursupersecretkey",". FlowFuse allows setting environment variables. Let’s start using them to understand how they work.",[10,26,27,28,31,32,35,36,39],{},"One of the options for the ",[17,29,30],{},"inject"," node is to inject a ",[17,33,34],{},"env variable",", short for; you guessed it: Environment Variable. In this case we’re going to one that’s pre-defined by Node-RED: ",[17,37,38],{},"NR_FLOW_NAME",". The name of each variable is in all caps by convention. When connecting this inject to a debug it prints “Flow 1” for me.",[10,41,42],{},[43,44],"img",{"alt":45,"src":46,"title":45},"Using an environment variable in Node-RED","\u002Fblog\u002F2023\u002F01\u002Fimages\u002Fnode-red-use-env-var.png",[10,48,49,50,53,54,57,58,60,61,64,65,67],{},"Leveraging environment variables can also be done with other nodes, like for example ",[17,51,52],{},"change",", ",[17,55,56],{},"switch",". Note however; you can set the ",[17,59,30],{}," node to output the value for ",[17,62,63],{},"FOO"," even when it doesn’t exist, but it doesn’t allow you to check in the switch node for example if ",[17,66,63],{}," exists.",[10,69,70,71,76],{},"Node-RED allows you to set environment variables, but not to change them when executing flows. If you want to update data during execution, look into using ",[72,73,75],"a",{"href":74},"\u002Fdocs\u002Fuser\u002Fpersistent-context\u002F","persistent context",". Node-RED doesn’t support Environment Variables like other programming environments do. When the flow is deployed the environment variables are replaced with the known values at that time. This is the biggest gotcha for most developers.",[78,79,81],"h3",{"id":80},"predefined-variables","Predefined variables",[10,83,84,85,53,88,91,92,94],{},"Our first example was using a predefined variable, exposed by Node-RED. As of 3.0 it exposes a few environment variables among which ",[17,86,87],{},"NR_NODE_NAME",[17,89,90],{},"NR_GROUP_NAME",", and ",[17,93,38],{},".",[10,96,97,101,102,105,106,110],{},[72,98,100],{"href":99},"\u002F","FlowFuse"," extends this list with for example a ",[17,103,104],{},"FF_PROJECT_ID"," allowing you to for example understand what group of instances sent a certain message, but also sets them for each ",[72,107,109],{"href":108},"\u002Fdocs\u002Fdevice-agent\u002Fintroduction\u002F","device agent",". This allows users to pinpoint which device sent a message, for example to update a dashboard accordingly.",[78,112,114],{"id":113},"managing-environments-variables","Managing environments variables",[10,116,117],{},"In FlowFuse it’s easy to manage variables set for instances. Under settings in the environment tab it’s a form to set them. You’ll have to restart your instances to make them available in the cloud, and update the target snapshot for devices. When done, these are available.",[10,119,120],{},[43,121],{"alt":122,"src":123,"title":124},"\"Setting a environment variable in FlowFuse\"","\u002Fblog\u002F2023\u002F01\u002Fimages\u002Fflowforge-set-env-var.png","Setting a environment variable in FlowFuse",[126,127,129],"h2",{"id":128},"boost-your-node-red-security-with-flowfuse","Boost Your Node-RED Security with FlowFuse",[10,131,132],{},"FlowFuse provides a comprehensive platform for managing and securing your Node-RED solutions. It includes advanced security features such as role-based access control, Multi-factor Authentication (MFA), Single Sign-On (SSO), and encryption to protect your data and enhance operational efficiency.",[10,134,135,136,94],{},"Learn how FlowFuse can boost your Node-RED security and streamline management through the ",[72,137,139],{"href":138},"\u002Fplatform\u002Fsecurity\u002F#application","FlowFuse security statement",[78,141,143],{"id":142},"explore-more-on-security","Explore More on Security",[145,146,147,154,160,166,172,178],"ul",{},[148,149,150],"li",{},[72,151,153],{"href":152},"\u002Fblog\u002F2024\u002F04\u002Frole-based-access-control-rbac-for-node-red-with-flowfuse\u002F","Role-Based Access Control (RBAC) for Node-RED with FlowFuse",[148,155,156],{},[72,157,159],{"href":158},"\u002Fdocs\u002Fuser\u002Fdevops-pipelines\u002F#protected-instances","Protecting Instances from Being Modified",[148,161,162],{},[72,163,165],{"href":164},"\u002Fblog\u002F2024\u002F07\u002Fhow-to-setup-sso-ldap-for-the-node-red\u002F","How to Set Up SSO LDAP for Node-RED",[148,167,168],{},[72,169,171],{"href":170},"\u002Fblog\u002F2024\u002F07\u002Fhow-to-setup-sso-saml-for-the-node-red\u002F","How to Set Up SSO SAML for Node-RED",[148,173,174],{},[72,175,177],{"href":176},"\u002Fblog\u002F2024\u002F03\u002Fhttp-authentication-node-red-with-flowfuse\u002F","Securing HTTP Traffic for Node-RED with FlowFuse",[148,179,180],{},[72,181,183],{"href":182},"\u002Fblog\u002F2024\u002F01\u002Fsoc2\u002F","FlowFuse is now SOC 2 Type 1 Compliant",{"title":185,"searchDepth":186,"depth":186,"links":187},"",2,[188,190,191],{"id":80,"depth":189,"text":81},3,{"id":113,"depth":189,"text":114},{"id":128,"depth":186,"text":129,"children":192},[193],{"id":142,"depth":189,"text":143},"md",{"navTitle":5,"excerpt":196},{"type":7,"value":197},[198],[10,199,12],{},true,"\u002Fblog\u002F2023\u002F01\u002Fenvironment-variables-in-node-red",{"title":5,"description":12},"blog\u002F2023\u002F01\u002Fenvironment-variables-in-node-red","IGwl38KKrOvVvz3fWLP3BN87G4nj68XmvDb5SP5IgLI",1780070550146]