Member-only story
Keep your code secure by using environment variables and env files
Securely load a file containing all of our app’s required, confidential data like passwords, tokens, etc
Your code needs to connect to a database. For this it needs a password to that database. How can you use this password in your app in such a way that you can both connect to the database and keep the password private?
This article shows you how to use an env file in your code. This file stores all of our confidential information. It can be loaded once so you have access to all of your private information like passwords anywhere in your app. In this article we’ll use Python to illustrate the workings of an env file but the principle applies for all programming languages.
At the end of this article you’ll:
- understand the advantages of using environment variables
- understand how environment variables work
- understand how we can load environment variables from an env file
Let’s code!
1. Why use environment variables?
There are two main reasons to use environment variable files:
1. safety
2. flexibility