View Source Nvir (Nvir v0.9.2)

Nvir is an environment variable loader and validator.

Please refer to the README for usage instructions.

Summary

Functions

Loads specified env files in the system environment. Intended usage is from config/runtime.exs in your project

Returns the value of the given var, transformed and validated by the given caster.

Returns the value of the given var, transformed and validated by the given caster.

Functions

See Nvir.Cast.cast/2.

Loads specified env files in the system environment. Intended usage is from config/runtime.exs in your project

Variables defined in the files will not override the system environment if they are already defined. To override the system env, please list your files under an :override key.

Files that do not exist are safely ignored.

Valid values are

  • A single binary string (a file path).

  • A list of paths.

  • A keyword list where the key are:

    • An environment name such as :dev or :test.
    • :* That will match any environment.
    • :override which will declare the files as system overrides.

    Values in keywords can be strings, lists, and nested keywords.

Examples

import Config
import Nvir

# Load a single file
dotenv!(".env")

# Load multiple files
dotenv!([".env", ".env.#{config_env()}"])

# Load files depending on environment
dotenv!(
  *: ".env",
  dev: ".env.dev",
  test: ".env.test"
)

# Load files with and without override
dotenv!(
  dev: ".env",
  test: ".env", ".env.test",
  override: [test: ".env.test.local"]
)

Returns the value of the given var, transformed and validated by the given caster.

Raises if the variable is not defined or if the caster validation fails.

Please see the README for available casters.

Link to this function

env!(var, caster, default)

View Source

Returns the value of the given var, transformed and validated by the given caster.

Returns the default value if the variable is not defined.

Raises if the caster validation fails.

Please see the README for available casters.