examples icon indicating copy to clipboard operation
examples copied to clipboard

Node.js confusing DOTENV_KEY example

Open RemyMachado opened this issue 1 year ago • 0 comments

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?

RemyMachado avatar Dec 03 '23 22:12 RemyMachado