What are Environment Variables?

Environment Variables have always been very handy and bit of a attraction whenever someone is building an application or working on an existing Project. They are basically the hints or handy tools of information which can be and should be used during the development of any Project.
No. But Seriously! What are Environment Variables?
Okay, So if I tell you that you are lost in a way and you don’t know where it goes and the only thing that you have right now that can help is the Map! How? Well, the paths in the map that are presented to you are basically telling you the exact direction where you should be headed to.

These paths can be used again and again, they can tell you the references to important road signs, currencies being used in that area, some emergencies phone numbers and maybe some shortcuts and modes of transport available.
In Simple words, Map in this case is acting as a quick tool for you to find a way when you are not living in a smart era of technology.
The important catch is, they are basically providing you a side support but can not fulfil all the needs of yours.
Okay. But how’s that related to Software development?

Interesting. If you are still here then you will be able to relate this part even better.
export const computer = "MacBook Pro 2017"
export const manufacturer = "Apple";
export const year = 2017;
export const website = "https://www.apple.com/";
export const description = "MacBook Pro elevates the notebook to a whole new level of performance and portability. Wherever your ideas take you, you’ll get there faster than ever with high‑performance processors and memory, advanced graphics, blazing‑fast storage, and more."
So for example, if I want to make an application related to Apple’s Macbook Pro and I need some important information across my whole application where I need it to use basic information more than 100 times, so instead of writing that information again and again, I can simply import these constants from a file where they are being saved and I can use it again and again across my whole application.
The Practical Example
I want to make an API call to the server,which has a url something similar to this: https://www.api.com?access_token=`hello%20world`.
But for that matter I need an access token, which is also available but I am too scared to push that code to my GitHub because the bots can easily access my account using that access token if I push it to GitHub.
So, What’s the solution?
Well, instead of passing the access token directly as a string into the URL, I can store that access token in a different config file from where I can import it and use it in the URL and adding that config file into gitignore. That way, there will be no way of accessing my token from anywhere except me.
Advantages of Environment Variables
- Lines of code is being saved and hence reducing the load and loading time.
- It follows DRY (Don’t repeat yourself), simply declare a constant or a function or any kind of storage variable where you want to store information which can help you to ease your development cycle.
- Reduces Frustration of copying and pasting the same information.
- Clean Code, Happy Code.
I hope, I somewhat made clear you about environment variables and why are they being used in development environment. If you have any suggestions, questions, please leave me a comment or tweet me at prateek_gogia.
This article is a part of a series on Environment Variables:
1. What are Environment Variables?
2. Environment variables in Create React App
3.Environment Variables : Webpack config using DefinePlugin
✉️ Subscribe to CodeBurst’s once-weekly Email Blast, 🐦 Follow CodeBurst on Twitter, view 🗺️ The 2018 Web Developer Roadmap, and 🕸️ Learn Full Stack Web Development.