website icon indicating copy to clipboard operation
website copied to clipboard

Revisit how we load environment variables

Open ferreiro opened this issue 7 years ago • 3 comments

In this PR @kwelch commented that he normally uses .env to create enviroment variables. I also read that Heroku good practises suggests to use that approach as well.

The goal of this issue is to research different possible ways to load env variables, and decide which one makes more sense for this project. Either keeping current approach or move to a new one.

Also, let's take advantage of this and use a better way to notify the user when sone of the variables are not found. Current approach is to throw an error (which is fine, because the app shouldnt be working if some env variables are not running) but I'd prefer if we can be more specific on the exception (for example checking all the env variables, and see if we have values for them. Otherwise notify which variables are missing and how to set them)

Example:

MISSING ENV Variables
------------------------
Hey! There are some variables in your project that you haven't set up. Without them, we can't run the server since some of the configurations may not work.

See this doc to know how to set your enviroment variable: <link to this repo README>
==================================================================
| GOOGLE_SECRET -> We use this to be able to access Google accounts. <optionally add a link to get this credentials>
------------------------------------------------------------------------------------------

ferreiro avatar Jan 10 '19 11:01 ferreiro

I'm thinking that managing the missing env variables can be a npm package itself! I'm sure more people have problems with this. What do you think @kwelch?

ferreiro avatar Jan 10 '19 11:01 ferreiro

I think using dotenv is a great plan. Some places use a .env.example to show what variables are there and sample versions. Also, we should default any of them if possible. I also think a readme is a great place to expand on it. All good approached.

Are far as notification and requiring them, I think that is interesting idea. Maybe it is something we can contribute back to dotenv as an optional field of what is required and so forth.

kwelch avatar Jan 11 '19 03:01 kwelch

I think using dotenv is a great plan. Some places use a .env.example to show what variables are there and sample versions. Also, we should default any of them if possible. I also think a readme is a great place to expand on it. All good approached.

Are far as notification and requiring them, I think that is interesting idea. Maybe it is something we can contribute back to dotenv as an optional field of what is required and so forth.

Yeah! Absolutely agree. Would love to contribute to dotenv for this ^_^

ferreiro avatar Jan 19 '19 18:01 ferreiro