Reputation: 61
I am working in node/express for server side and using Glitch for building my APP. Suppose my project needs some sensitive credential to be used, lets say my userid and password. I create a .env file, assign those values to local environmental variables like this.
.env
USERID="myuserid"
PASS="mypassword"
Then in my project i will use process.env.USERID and process.env.PASS wherever i need. Fine till now.
If i want to export my project to github, without exposing my .env contents, i can include .env file in .gitignore. By doing this Git ignores my .env file. I dont need to worry about my sensitive data going public.
Then why would i need dotenv package. All the articles related to dotenv says that it solves the problem of exposing our sensitive credentials to public. Even when using the dotenv module in my project I am supposed to include .env in .gitignore file. So what significance does dotenv module make ?
Upvotes: 4
Views: 248
Reputation: 164
The dotenv module is nothing more than a way to inject values as if they were environment variables. The idea is that for development environments you use a .env file, but for production environments you would use actual environment variables. AWS, Heroku, and Docker all have their own respective configuration methods for managing environment variables and you would use that for production, not an actual .env file.
Upvotes: 3