Problem:
When execute "node path/to/files/index.js", dotenv can't find .env file and then environment variables are undefined, but if i do "cd path/to/file" and then execute "node index.js", works nicely
Am i doing something wrong?
@brnx1 the Readme.md explain this case, see below:
Options
Path
Default:
path.resolve(process.cwd(), '.env')You may specify a custom path if your file containing environment variables is located elsewhere.
require('dotenv').config({ path: '/custom/path/to/.env' })
The process.cwd() method returns the current working directory of the Node.js process.
@matheusalbino thanks for calling out the readme. I going to close this issue for now @brnx1 please let me know if that did not fix the issue.
Most helpful comment
@brnx1 the Readme.md explain this case, see below:
The
process.cwd()method returns the current working directory of the Node.js process.