Environment Variables
Environment variables let users define parameters in the runtime environment of Edge Computing applications and use them in their code. These variables must be defined as a valid JSON value.
Note that these values don't have to be objects; they can be any valid JSON value, such as an integer, a decimal number, an array, a boolean, or even a string with a JSON structure.
For example, all of the following are accepted as valid values:
"encrypted_value"
992647896
true
[1, 2, 3]
{ "API_KEY": "abcdef123456" }
By defining an environment variable in Arvancloud Edge Computing, you can access it in all instances of an Edge Computing application. This way, you don't need to define the variable again in your code and can use it in different parts of the application.
Note that each environment variable can be used only in the application in which it is defined, and it is not available in other Edge Computing applications.
For example, imagine you have defined a variable named API_URL that holds the URL of a web service. This variable can be defined in JSON as follows:
"https://api.example.com"
This variable can be used only in the application in which it is defined. To use it in other applications, you need to register it separately in each app.
Defining an Environment Variable
To define an environment variable, go to the Arvancloud Edge Computing panel and click the application you want to define the variable for.
Select the settings section and click the New Variable button.
On the page that opens, enter the name and value of the variable.
On the same page, you can choose to encrypt your variable. When a variable is encrypted, its value can no longer be viewed and is only available at runtime.
For example, suppose a user has a variable named API_KEY that contains a security key. This variable can be placed in the runtime environment in encrypted form, so that its value is only accessible while the application is running.
Note that after you encrypt a variable, you can no longer view it in the panel.
After defining the variable, click Publish.
Note that a reserved variable named EC_URL is defined by default in all Edge Computing applications. This variable shows the runtime address of the application on Edge Computing and cannot be overwritten or reused by users.
Using Environment Variables in Code
Imagine you have defined an environment variable named test-variable with the following value:
{ "api_key": "abcdef123456" , "status":"statustest"}
To access the values of this variable in your code, you can use the following statement:
console.log(env.test.status);
The output of this code in the console is as follows:
statustest