Description
Extract from the exercise:
The .env file is a hidden file that is used to pass environment variables to your application.
...
We write a .env file holding a VAR=something. We can console log this variable, by running "Run" in a repl.it file.
But this is not the standard Node.js behavior. npm start or node server.js won't load any variable unless we include the dotenv package. So If any user tries to emulate that project locally, it won't work the same.
I may be missing something simple, but just find it strange, and asking in repl.it didn't help much so far.
Add a Link to the page with the problem:
Because it's a hidden file the only way is to build it yourself. A way is to create a new repl.it and a .env file, then console logging the value.
Directory Tree Image

Can you assign this issue to me ?
@TAbhay We have yet to determine if this is a bug. We will attach a help wanted label once we make the determination of what needs to done.
To address the issue:
I believe repl.it (like Glitch) parses the environment variables behind the scenes. It is true that local development (and possibly some hosting providers) will require the use of the dotenv package (or something similar). It is worth adding a note to this challenge explaining this?
@nhcarrigan This is the same issue that was present on the Advanced Node challenges (and probably many others). Maybe we just need to update the boilerplate to already have the dotenv package in package.json and add the require('dotenv').config() line as the first line of the myApp.js file.
To address the issue:
I believe repl.it (like Glitch) parses the environment variables behind the scenes. It is true that local development (and possibly some hosting providers) will require the use of the
dotenvpackage (or something similar). It is worth adding a note to this challenge explaining this?
I - as someone that is learning - believe it is. But I cant speak for everyone. Also, I asked on repl.it, and no one gave me a clear answer of what happens when you press "Run" (cause it should just run node start but something else it's going on there). (Plus, I mean, the whole point of the exercise is to learn to do it yourself right?)
And if you open up the event run from "Run" it's just impossible to understand, not sure if there is any easier way to inspect what's running there.
Just do
1) npm install dotenv
2) Add require('dotenv').config() in myApp.js file
3) Add .env file with PORT = 3000
4) Now npm start
It will work
Just do
1. **npm install dotenv** 2. Add **require('dotenv').config()** in myApp.js file 3. Add **.env** file with **PORT = 3000** 4. Now **npm start** It will work
If you read the issue, you'll find out I've done that already. Anyways that should be clear from the exercise. But that's not the main problem. The problem is that because something is loaded in the background, understanding how it works is made more difficult.
For example, do you know why console logging a .env variable runs fine without the .dotenv package? You might do, I doubt someone that is learning will.
@RandellDawson I think that's probably the best approach. 馃檪
That makes sense to me, too. We'd like to be as platform agnostic as possible and dotenv helps with that.
It might be worth re-wording the challenge slightly, too:
This file is secret, no one but you can access it, and it can be used to store data that you want to keep private or hidden.
to
This file should be kept out of version control, then it can be used to store data that you want to keep private or hidden.
and
The environment variables are accessible from the app as
to
The
dotenvpackage makes the contents of.envaccessible in the app as
Sounds like we are set on:
1) Add dotenv to the package.json
2) Require it in the appropriate location
3) Use Oliver's wording (above), for clarity
Hey guys, linked a pr for adjusting the boilerplate code above, if you'd like to review : )