dist/index.js
// Populates process.env from .env file
Populates process.env from .env file
Populates process . env from . env file
function config (options) {
  let dotenvPath = path.resolve(process.cwd(), '.env')
  let encoding = 'utf8'
  const debug = Boolean(options && options.debug)
  const override = Boolean(options && options.override)
  if (options) {
    if (options.path != null) {
      dotenvPath = _resolveHome(options.path)
    }
    if (options.encoding != null) {
      encoding = options.encoding
    }
  }
  try {
    const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }))
    Object.keys(parsed).forEach(function (key) {
      if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
        process.env[key] = parsed[key]
      } else {
        if (override === true) {
          process.env[key] = parsed[key]
        }
        if (debug) {
          if (override === true) {
            _log(`"${key}" is already defined in \`process.env\` and WAS overwritten`)
          } else {
            _log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`)
          }
        }
      }
    })
    return { parsed }
  } catch (e) {
    if (debug) {
      _log(`Failed to load ${dotenvPath} ${e.message}`)
    }
    return { error: e }
  }
}
function config ( options ) { let dotenvPath = path . resolve ( process . cwd ( ) , '.env' ) let encoding = 'utf8' const debug = Boolean ( options && options . debug ) const override = Boolean ( options && options . override ) if ( options ) { if ( options . path != null ) { dotenvPath = _resolveHome ( options . path ) } if ( options . encoding != null ) { encoding = options . encoding } } try { const parsed = DotenvModule . parse ( fs . readFileSync ( dotenvPath , { encoding } ) ) Object . keys ( parsed ) . forEach ( function ( key ) { if ( ! Object . prototype . hasOwnProperty . call ( process . env , key ) ) { process . env [ key ] = parsed [ key ] } else { if ( override === true ) { process . env [ key ] = parsed [ key ] } if ( debug ) { if ( override === true ) { _log ( ` ${ key } \` \` ` ) } else { _log ( ` ${ key } \` \` ` ) } } } } ) return { parsed } } catch ( e ) { if ( debug ) { _log ( ` ${ dotenvPath } ${ e . message } ` ) } return { error : e } } }
Populates process.env from .env file
Populates process . env from . env file
// Specifying an encoding returns a string instead of a buffer