Skip to the content.

OneBlink API CLI

Environment Variables

Environment variables help define values which you may not want hard-coded in your source. They allow you to customize code behavior depending on the environment in which it is running.

Variables are stored inside .blinkmrc.json and these key/value pairs will be available to your code via process.env.

Scoped vs Unscoped

We allow for variables to be scoped to a specific environment:

.blinkmrc.json

The following configuration 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 --env flag used during deployment

oneblink api deploy --env dev
module.exports = function handler() {
  if (process.env.MY_VARIABLE_SCOPED === 'dev scoped value') {
    // It works! :)
  }
}

Notes

Referencing Environment Variables

To reference environment variables, use the ${MY_VARIABLE} syntax in your .blinkmrc.json configuration file.

.blinkmrc.json

The following configuration will set process.env.MY_VARIABLE at runtime to the value of MY_EXISTING_VARIABLE during the deploy process:

{
  "server": {
    "variables": {
      "MY_VARIABLE": "${MY_EXISTING_VARIABLE}"
    }
  }
}
export MY_EXISTING_VARIABLE="value"
oneblink api deploy
module.exports = function handler() {
  if (process.env.MY_VARIABLE === 'value') {
    // It works! :)
  }
}

Notes