Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku node.js - no such file or directory, open '.env'

Tags:

node.js

heroku

I built an app using node.js and deployed it onto heroku but I keep getting the error in my heroku logs:

{ [Error: ENOENT: no such file or directory, open '.env'] errno: -2, code: 'ENOENT', syscall: 'open', path: '.env' }

This means that it is missing the environment variables. However, I did set my environment variables in heroku/dashboard/config_vars. Furthermore, if i type: heroku config, it shows me a list of my environment variables...

Does anyone know what might be happening or what I can do?

Note - I added '.env' to my '.gitignore'.

Thx in advance!

like image 476
Trung Tran Avatar asked Jul 06 '16 00:07

Trung Tran


1 Answers

Sounds like somewhere in your code you are trying to open the .env file.

You should not be doing that. To access an environment variable called MY_ENV_VAR, simply refer to process.env.MY_ENV_VAR in your node.js code.

Adding .env to .gitignore is correct.

In your development environment, you set the values of your environment variables in .env. These will be passed to your app by "heroku local" or "foreman start".

On Heroku, you set the values of your environment variables via "heroku config" (or via the Heroku dashboard), as you have done.

Bottom line: Everything you have done is correct, EXCEPT for the fact that your node.js app seems to be trying to explicitly open the .env file. That is a mistake!

like image 179
Yoni Rabinovitch Avatar answered Oct 03 '22 08:10

Yoni Rabinovitch