In the last HTTP API I’ve built, I decided to drop the environment config files. Although it was how things were generally done, I thought about it and wondered why I would expose sensitive information like my database password and AWS keys in my codebase. After a little consideration, I thought about using environment variables, instead. When thinking it through, I figured it was the best way to go. I wouldn’t have to worry about setting up an environment fallback structure. In this situation I would just have to set the variables in the environment, and refer to the variables. I can also keep sensitive information out of my codebase for security concerns.

##Setting Environment Variables

Because I’ve made a conscious decision to keep my development unix-based, I do not not know enough about Windows servers to comfortably include them in my blog posts. However, creating an environment variable in Unix is easy, just use the export command. Remember that when you close the terminal instance, you will loose the environment variable. Save it to your .zshrc, .bashrc, .bash_profile, or which ever file you may be using.


export VAR_NAME="value"

##Accessing Environment Varibales Here is how the environment variables are accessed in some languages I use/experiment with. Some languages (like PHP) have a lot of frameworks that have wrappers for doing this. I would suggest to use the wrappers, they are usually cleaner.






import "os"

func main() {


#include <cstdlib>

int main()






import os