dotenv can't find .env file

Created on 14 Jan 2020  路  2Comments  路  Source: motdotla/dotenv

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?

Most helpful comment

@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.

All 2 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ycmjason picture ycmjason  路  4Comments

Jakobud picture Jakobud  路  3Comments

Vandivier picture Vandivier  路  3Comments

marcusradell picture marcusradell  路  3Comments

datasmurfen picture datasmurfen  路  5Comments