Open NouraldinS opened 5 years ago
i use it to can deal with the variable in file .env like process.env.DATABASE_URL_LOCAL
DATABASE_URL_LOCAL not exist in process.env i need to call it from the .env file , and put it in app file to require it once and can access to all other files in my application
@engshorouq True, but it, in it's current place, is useless, because you've already called it in your db_connection
, so, either remove it from your app
, or from your db_connection
.
https://github.com/FACG6/CMSPosts/blob/6df00bcc761329d8e4c90eca4f5a99ebb70d379d/src/app.js#L1
First line in your
app.js
you requireddotenv
, because mostly, you thought it is needed whenever you callprocess.env
. Which isn't true.process.env
is a global system variable that has your environment variables. (typeenv
to your terminal and press enter) This variable exists even withoutdotenv
installed or any other library,process
to Node is something likewindow
to Javascript in the browser.And if you typed env in your terminal, pressed enter, and seen what's there, then console logged the
process.env
object, you'll find they're the same.This leaves us with the last detail, what does
dotenv
does? It adds a property to yourprocess.env
object. The property added in your.env
file.