dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

Unable to find environment variables when they are stored outside of the "start" context

Open womj opened this issue 4 years ago • 6 comments

file structure

package.json .env packages/ --project1/ ----package.json ----start.js (this is where we call dotenv.config())

cannot find the .env file if the start command is run from the package.json in project1.

If we use a start command node packages/project1/start.js in the outer directory the environment variables are loaded fine.

womj avatar Jun 06 '22 17:06 womj

You need to provide the path to the .env in the config method documentation here: https://github.com/motdotla/dotenv#path

code example: require('dotenv').config({ path: '/custom/path/to/.env' })

JR33D avatar Jun 18 '22 03:06 JR33D

It would be a pretty simple add for the package to use something like https://www.npmjs.com/package/find-up

shellscape avatar Jan 24 '23 17:01 shellscape

It's a fair suggestion but it could cause unintended side effects. dotenv is pretty easy to configure. Just point to a .env file. We'll leave as is.

motdotla avatar May 04 '23 21:05 motdotla

@motdotla I think at this point you should amend the readme that dotenv is considered stable and has entered maintenance. I haven't seen you welcome a significant change in some time. It would be disingenuous to accept feature issues/requests when most, if not all, will be rejected with a similar response as made above

shellscape avatar May 04 '23 21:05 shellscape

@womjdmg @JR33D and anyone else who may need this functionality; a while back I created https://github.com/shellscape/dot/tree/master/packages/env which combined several dotenv packages along with find-up to resolve the shortcomings of this package. You may find it useful.

shellscape avatar May 04 '23 21:05 shellscape

dotenv has been stable since the year 2015. We've certainly added many features since then but rejected many more.

motdotla avatar May 05 '23 15:05 motdotla