Configuring your Environment Variables

Environment variables help define values which you may not want hard-coded in your source. They allow you to customise code behaviour depending on the environment in which the code is executed.

These variables are stored in your blinkmrc.json file, and are made available to your code via process.env.

Scoped vs Unscoped

We allow for your variables to be scoped to a specific environment.

Unscoped variables are static, and will not change between your different environments.

Scoped variables allow you to define the variable as an object, with a different value for each environment of your project. This is useful for accessing values such as Database connection strings or API endpoints, which may differ between them.

The following example shows how you can define both scoped and unscoped variables in your blinkmrc.json file, which will allow process.env.MY_VARIABLE and process.env.MY_VARIABLE_SCOPED to be available in code:

{
  "server": {
    "variables": {
      "MY_VARIABLE": "unscoped value",
      "MY_VARIABLE_SCOPED": {
        "dev": "dev scoped value",
        "test": "test scoped value",
        "prod": "prod scoped value"
      }
    }
  }
}

The value of process.env.MY_VARIABLE_SCOPED will depend on the value of the --env flag used during the bm server deploy step, which we'll cover next.

Next Step

Server CLI Commands