Skip to content
On this page

Env

Overview

Loads configuration from environment varibles.

Usage

bash
export PORT=5432
export HOSTS=localhost:1234,localhost:5678
typescript
import * as Konfig from "@willsoto/node-konfig-core";

const loader = new Konfig.EnvLoader({
  envVars: [
    {
      accessor: "port",
      envVarName: "PORT",
    },
    {
      accessor: "hosts",
      envVarName: "HOSTS",
      arraySeparator: ",",
    },
  ],
});

// Loads the following structure into the store
store.get("port"); // "5432"
store.get("hosts"); // ["localhost:1234", "localhost:5678"]

Options

NameRequiredDescription
envVarsyesSee EnvVar

EnvVar

NameRequiredDescription
accessoryesWhere to place the environment variable in the store. Can be in dot notation for nested structures.
envVarNameyesThe name of the environment variable to look up.
arraySeparatornoIf the value is meant to be an array, how should it be converted into a native JS array.