Have ideas to improve npm?Join in the discussion! »

    string-env-interpolation
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    string-env-interpolation

    Use string interpolation to provide Environment Variables.

    Installation

    yarn add string-env-interpolation
    npm install string-env-interpolation
    

    Usage

    Let's say we have a config file: config.yaml.

    debug: ${DEBUG:false}
    name: ${NAME:"Development"}
    user: ${USER}

    Our library wants to be able to consume environment variables in index.js.

    import { env } from "string-env-interpolation";
    import { readFileSync } from "fs";
     
    const content = env(readFileSync("./config.yaml", "utf-8"));
     
    console.log(content);

    Outputs:

    DEBUG=true USER=kamil node index.js
     
    # Output 
    debug: true
    name: Development
    user: kamil
     
     
     
    NAME=Production USER=kamil node index.js
     
    # Output 
    debug: false
    name: Production
    user: kamil

    Keywords

    none

    Install

    npm i string-env-interpolation

    DownloadsWeekly Downloads

    1,053,768

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.96 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar