config() accetps any path
ShahriarKh opened this issue · 1 comments
ShahriarKh commented
Config path accepts any string. I tried:
dotenv.config({ path: 'random-file-name.jpg' })
and the code executed without any errors!
Currently, I'm using this hacky way to ensure that correct env file is loaded:
if (!dotenv.config({ path: '.env.local' }).parsed) {
// throw an error or something...
}
But I believe the path
should do some checking to only allow .env.*
files and throw an error if the file is invalid.
👀 I think this PR is related: #651
motdotla commented
We choose not to throw an error because in production the .env
file won't be there.
If you'd like to throw an error, you can do a file check first using node's fs lib. then pass to dotenv.