Skip to content

Node.js confusing DOTENV_KEY example #11

@RemyMachado

Description

@RemyMachado

Hey, I'm not sure I understand the current example of Node.js DOTENV_KEY setup.

The current README.md:

node index.js

// console.log(result.parsed) // { HELLO: 'Universe' }
// console.log(result.parsed.HELLO) // 'Universe'
// console.log(process.env.HELLO) // undefined (as intentioned)

When I remove the .env file to try loading it with the vault and the DOTENV_KEY the project fails to load the vault.
I was using:

const envName = process.env.NODE_ENV
const envFilePath = `.env.${envName}`
dotenv.config({ path: envFilePath })
console.info('environment loaded:', envFilePath)

I thought maybe I should only use the following:

dotenv.config()

But none of these two approach worked.
The commands I have tried without success:
$ DOTENV_KEY=*** yarn start
$ DOTENV_KEY=*** NODE_ENV=development yarn start

Note that DOTENV_KEY and NODE_ENV correctly appear inside process.env while running, but the env file is not loaded.

In the meantime, I'll simply decrypt the vault with the decrypt command, but I thought that the magic DOTENV_KEY was cool to use.

Also I'm not sure how dotenv.config() is supposed to check for the DOTENV_KEY when it's related to the dotenv-vault feature. Shouldn't it be replaced with dotenvVault.config() while adding dotenv-vault as a dependency to the project?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions