motdotla / dotenv

Loads environment variables from .env for nodejs projects.
https://www.dotenvx.com
BSD 2-Clause "Simplified" License
19.26k stars 861 forks source link

Ignore .env.example #825

Closed FlawTECH closed 6 months ago

FlawTECH commented 6 months ago

Hi, I have a project in which I supply a .env.example with the default values for easier deployment. Anyone who wants to deploy this project then has to copy this file to a .env file and adjust configuration as needed.

I was expecting dotenv to automatically load the .env file by default, but it seems .env.example is prioritized if present over .env. How do I prevent this from happening ?

I tried supplying { path: ['.env'] } but even that doesn't seem to work.

motdotla commented 6 months ago

@FlawTECH are you sure it does this? I've just double checked:

// index.js
require('dotenv').config()
console.log('Hello ' + process.env.HELLO)
# .env.example
HELLO="example"

output of node index.js

Hello undefined

P.S. you can use dotenvx genexample to auto-generate your .env.example files

FlawTECH commented 6 months ago

Apologies, you are indeed correct. I tried in a clean environment (something I should have done in the first place) and I don't reproduce the issue. Something must be poisoning my main project's environment.

Sorry for the trouble.