Unable to find environment variables when they are stored outside of the "start" context
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.
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' })
It would be a pretty simple add for the package to use something like https://www.npmjs.com/package/find-up
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 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
@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.
dotenv has been stable since the year 2015. We've certainly added many features since then but rejected many more.