Use Environment Variables from .env in custom node client html file

I am developing a custom Node in Node-RED. This node will allow users to interact with different environments (like development, QA, and sandbox) by making HTTP requests to a backend API.

I want to make the default environment selection dynamic based on the NODE_ENV variable defined in my server's .env file. The NODE_ENV variable can be set to development, qa, or sandbox, and I want the environment field in the configuration form to be pre-filled with the corresponding value from this variable.

Hi and welcome to the forum.

What have you tried so far? Are you familiar with Node.js? And how are you starting up Node-RED?

tried process.env but it says process is undefined.

The editor has no access to process variable.

You need to send the value of your environment variable from the runtime to the editor. Example with the udp node:

  • Editor
  • Runtime
RED.httpAdmin.get('/udp-ports/:id', RED.auth.needsPermission('udp-ports.read'), function(req,res) {
        res.json(Object.keys(udpInputPortsInUse));
    });

What would be the API call for env variables.?

Woops, forgot it

const env = RED.util.getSetting(node, "envName")

And something like your-node-type/env

I added this const env = RED.util.getSetting(node, "NODE_ENV"). editor html file But it doesnt work. RED.util is undefined.

This fonction is for the runtime (your js file).

As I said above, the only way you have in the editor is the httpAdmin API.

Solved by DM.