dotenv but it also search through parent directories

Usage no npm install needed!

<script type="module">
  import dotenvUp from '';


npm version NpmLicense


    yarn add dotenv-up


    require('dotenv-up')(3, true, 'sandbox/server.js');
     * Use like
     *     require('dotenv-up')(2); // 2 - default assigned to 'deep' parameter
     *     require('dotenv-up')(2, false); // second param is "debug" flag - to show on not show each step on the screen
     *     require('dotenv-up')(2, false, 'name of load'); // plain text to describe individual use of this library
     *     require('dotenv-up')({
                path            = process.cwd(),
                envfile         = '.env',
                override        = true, // override values in process.env
                deep            = 1,
                startfromlevel  = 0,
                justreturn      = false, // don't add found values to the process.env global object
                ... other dotenv options
     *     });
     * @param opt
     * @param debug (def: true)
     * @param name
     * @returns {} - object with all extracted variables

Docker use

    override    : false, // don't override existing parameters in process.env by those from .env file
    deep        : 3,
}, true, 'sandbox/server.js');

// instead of:

require('dotenv-up')(3, true, 'sandbox/server.js');
// because 'override' flag is by default true



If you need to include other file that use internally again dotenv-up tool in override mode but you don't want those changes of process.env affect proce.env in you'r scope, do:

const ttt = {...process.env};
require('./lib/lib.js') // with its own require('dotenv-up')(1);
process.env = ttt;