Custom extension (node) Set or change .env variable module

This is a simple module to manage .ENV variables.

With this extension you can change .ENV variable values, create new .ENV variables or simply return the value of an existing .ENV variable

Install as per these instructions.

DONT FORGET A WAPPLER RESTART AFTER INSTALL

Once installed the use will see a new server connect group called "Environment"

image

within this group you will see:

image

Add the component:

Enter the mandatory environment variable name, i enter "MY_NAME"

.ENV variables should be declared in CAPITALS, the module will force any name entered into capitals unless the "Allow Mixed case" checkbox is checked.

Next add a value, i add my name, "Brian English"

image

Lastly check "Output" if you wish to see the result

image

On running the API action, the module performs the following actions:

  1. if the .ENV variable exists and no value is sent from the module, it simply returns the current value
  2. If the .ENV variable exists and a value is sent, it's value is changed
  3. If the .ENV variable does not exist, it is created and it's value set

On this case the .ENV variable MY_NAME is created and given the value of "Brian English".
In all cases the module returns the current value of the .ENV variable in exit

{"Env1":"Brian English"}

NOTE. These changes are not written to app/config/config.json, they are dynamic in nature.

Changes will be lost, default values restored and new variables cleared on server start

3 Likes

Hi Brian.
ENV variables are by nature not supposed to be set from the code - they should only be used in the code - from what my understanding is.
What would be the use case for creating ENV variables or changing its values in runtime?

1 Like

Ask jim

Ah! Sorry to say but your help here is promoting bad coding practice. :sweat_smile:

Storing things like these in the DB is the best practice - as suggested on the post.
Or even in a file on the server, and read/write data from file - this would require custom extensions though.

2 Likes

I call it enabling choice.