Documentation
    Preparing search index...

    Env parser parses the environment variables from a string formatted as a key-value pair seperated using an =. For example:

    PORT=3333
    HOST=127.0.0.1

    The variables can reference other environment variables as well using $. For example:

    PORT=3333
    REDIS_PORT=$PORT

    The variables using characters other than letters can wrap variable named inside a curly brace.

    APP-PORT=3333
    REDIS_PORT=${APP-PORT}

    You can escape the $ sign with a backtick.

    REDIS_PASSWORD=foo\$123
    
    const parser = new EnvParser(envContents)
    const output = parser.parse()

    // The output is a key-value pair
    Index

    Constructors

    • Creates a new EnvParser instance

      Parameters

      • envContents: string

        Raw environment file contents

      • appRoot: URL

        Application root directory URL

      • Optionaloptions: { ignoreProcessEnv: boolean }

        Parser options

      Returns EnvParser

    Methods

    • Define an identifier for any environment value. The callback is invoked when the value match the identifier to modify its interpolation.

      Parameters

      • name: string

        The identifier name

      • callback: (value: string) => string | Promise<string>

        Callback function to process the identifier value

      Returns void

      use EnvParser.defineIdentifier instead

    • Define an identifier for any environment value. The callback is invoked when the value match the identifier to modify its interpolation.

      Parameters

      • name: string

        The identifier name

      • callback: (value: string) => string | Promise<string>

        Callback function to process the identifier value

      Returns void

    • Define an identifier for any environment value, if it's not already defined. The callback is invoked when the value match the identifier to modify its interpolation.

      Parameters

      • name: string

        The identifier name

      • callback: (value: string) => string | Promise<string>

        Callback function to process the identifier value

      Returns void

    • Remove an identifier

      Parameters

      • name: string

        The identifier name to remove

      Returns void

    • Parse the env string to an object of environment variables.

      Returns Promise<DotenvParseOutput>

      Promise resolving to parsed environment variables