dotenv-packed

    1.2.2 • Public • Published

    dotenv-packed

    NPM version Travis (.org) Coveralls github NPM

    Pack dotenv and some of its extensions (dotenv-expand and dotenv-conversion) into one.

    Install

    npm install dotenv-packed

    Usage

    # process.env
    
    DEBUG=false
    
    # .env file
    
    VARIABLE_1=value_1
    VARIABLE_2=yes
    
    // .js file
    
    import {parseEnv, getEnv} from 'dotenv-packed'
    
    // ** Basic
    const {parsed} = parseEnv() // parse, expand, convert variables
    const env = getEnv()
    
    console.log(parsed) // (object) { ... , VARIABLE_1: 'value_1', VARIABLE_2: true, ... }  
    console.log(process.env) // (object) { ... , DEBUG: 'false', VARIABLE_1: 'value_1', VARIABLE_2: 'true', ... }
    console.log(env) // (object) { ... , DEBUG: false, VARIABLE_1: 'value_1', VARIABLE_2: true, ... } 
    
    console.log(process.env.DEBUG) // (string) 'false'
    console.log(process.env.VARIABLE_1) // (string) 'value_1'
    console.log(process.env.VARIABLE_2) // (string) 'true'
    console.log(process.env.NOT_SET) // undefined
    
    console.log(env.DEBUG) // (boolean) false
    console.log(env.VARIABLE_1) // (string) 'value_1'
    console.log(env.VARIABLE_2) // (boolean) true
    console.log(env.NOT_SET) // undefined
    
    console.log(getEnv('DEBUG')) // (boolean) 'false'
    console.log(getEnv('VARIABLE_1')) // (string) 'value_1'
    console.log(getEnv('VARIABLE_2')) // (boolean) true
    console.log(getEnv('NOT_SET')) // null
    console.log(getEnv('NOT_SET', 'default_value')) // (string) 'default_value'
    
    // ** With extra configuration options of `dotenv` or `dotenv-conversion`
    const {parsed} = parseEnv({
        dotenvConfigOptions: { ... },
        dotenvConversionConfigOptions: {
            specs: {
                VARIABLE_1(value) {
                    return value.toUpperCase()
                },
            },
        },
    })
    const env = getEnv()
    
    console.log(parsed) // (object) { ... , VARIABLE_1: 'VALUE_1', VARIABLE_2: true, ... }
    console.log(process.env) // (object) { ... , DEBUG: 'false', VARIABLE_1: 'VALUE_1', VARIABLE_2: 'true', ... }
    console.log(env) // (object) { ... , DEBUG: false, VARIABLE_1: 'VALUE_1', VARIABLE_2: true, ... }
    
    console.log(process.env.DEBUG) // (string) 'false'
    console.log(process.env.VARIABLE_1) // (string) 'value_1'
    console.log(process.env.VARIABLE_2) // (string) 'true'
    console.log(process.env.NOT_SET) // undefined
    
    console.log(env.DEBUG) // (boolean) false
    console.log(env.VARIABLE_1) // (string) 'VALUE_1'
    console.log(env.VARIABLE_2) // (boolean) true
    console.log(env.NOT_SET) // undefined
    
    console.log(getEnv('DEBUG')) // (boolean) false
    console.log(getEnv('VARIABLE_1')) // (string) 'VALUE_1'
    console.log(getEnv('VARIABLE_2')) // (boolean) true
    console.log(getEnv('NOT_SET')) // null
    console.log(getEnv('NOT_SET', 'default_value')) // (string) 'default_value'

    Features

    See configuration options and features at their own repositories:

    Install

    npm i dotenv-packed

    DownloadsWeekly Downloads

    43

    Version

    1.2.2

    License

    MIT

    Unpacked Size

    11.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • linhntaim