Use environment variable to override json value in module


The environment variable for the module needs to be prefixed with BP_MODULE. Append the name of the module you want to override the variable BP_MODULE_<MODULE_NAME>. Choose the variable in the config file to override BP_MODULE_<MODULE_NAME>_<PROPERTY_KEY> = { key: value }

Modified MODULE JSON value with an environment variable

I dig in the code and find this piece of code.

    for (const option of getPropertiesRecursive(schema)) {
      const envOption = `${moduleId}_${option}`.replace(/[^A-Z0-9_]+/gi, '_')
      const envKey = `BP_MODULE_${envOption}`.toUpperCase()

Botpress is looking at the scheme of every loaded module. It transforms the value into a variable called BP_MODULE_<MODULE_NAME>_<PROPERTY_KEY>

The GetPropertiesRecursive transform the schema value into a dot notation primaryKey.secondKey

After this, the dot notation value is transformed into UPPERCASE value and the . is replaced by _

For example, Iā€™m using the NLU module and I want to override the nluServer from the config

  "$schema": "../../assets/modules/nlu/config.schema.json",
  "nluServer": {
    "autoStart": true
  "ducklingURL": "",
  "ducklingEnabled": true,
  "preloadModels": true,
  "languageSources": [
      "endpoint": ""
  "modelCacheSize": "850mb",
  "maxTrainingPerInstance": 1,
  "queueTrainingOnBotMount": false,
  "legacyElection": false

The value generated by the config-reader will be BP_MODULE_NDU_NLUSERVER

The value of the BP_MODULE_NDU_NLUSERVER could be a JSON or a String

BP_MODULE_NLU_NLUSERVER = { autoStart: false }