create account

Steps to use .env files in your Quasar framework project by bala41288

View this thread on: hive.blogpeakd.comecency.com
· @bala41288 ·
$6.23
Steps to use .env files in your Quasar framework project
Vue has always been very comfortable for me and the Quasar framework is a nice wrapper on top of Vue giving us all the necessary things to build a website from scratch. If you already know Vue, then using Quasar and getting your first project up and running is quite simple. I'm not going to go into details of that in this article. Let's stick to the context of using .env files to store your environment variables in this article. 

![image.png](https://images.hive.blog/DQmQh5wMyJSKadv5MYg4WN3r5xKG2suL51NgSiaDB4bs3x7/image.png)

Before we start with the steps, I would like to brief a little on the need for .env files. Most of the time we will have some need to keep a secret key or an API key in the front end code to use them and pass them to the API to get our data. Hardcoding those key values directly can be one option but it is always good to not hardcode sensitive information for security reasons. If we are working on a firebase project, we don't have to worry about keeping the API keys visible in the front end because that's how they recommend it saying that we don't have any vulnerabilities. There are other ways to handle the security aspects when it comes to firebase especially with the help of database rules. 

Even if we are using Vue with firebase, we might have a need to use .env files. Coming back to the topic, .env files help us store the variables and the variables get loaded during the run time. Let's go step by step. 

## Creating .env files

When I say creating .env files, these are temporary files that stay offline and will not be added to the git. We have to make sure that the .env files are added to the .gitignore file. We can create multiple .env files and have an envparser to choose the specific variables based on the environment we are using. That is what we are going to see in this article. I usually have two .env files. 

```
.env
.env.dev
```

Some people also use a different structure where they can keep it in the below structure. 

```
.env
.env.dev
.env.staging
.env.prod
```
The above structure can work well for enterprise products and I believe that it is all how we use them inside our config file. 

## Creating envparser file

Forget about these names. You can have your own names in these files. The content of the file is what really matters. The content of this envparser is quite simple. I use a library called dotenv that copies the variables from .env files and loads them during runtime. This will keep the variables in a secure place where the web application can access. Below is the code snippet of my `envparser.js` file. 

![image.png](https://images.hive.blog/DQmRe8wVE5wgVTMuNU5ZADbMgJZGT5cXTtyrZxn48HqyWqm/image.png)

The above code identifies in which mode the execution happens and based on that it uses the respective .env file. In my case, I have used only two .env files. So, I will be keeping my development-related environment variables in .env.dev file and it will get loaded when I do the command `quasar dev` and the other common .env file will be loaded for other modes. 

## Configuring Quasar.config file

Next and the final step is to just use the above envparser.js file in the quasar.config file. We have to first require this file and then add it inside the build portion of the module.exports. 

`const  envparser = require('./envparser.js');`

`env:  envparser(),`

While trying to do all these things I learned a few things. I noticed that we will not be able to read the env variables directly in the config file. I tried a few steps to get the values and I got undefined status. The above tutorial is not only specific to the quasar framework but even for people using direct Vue, this should be a good solution for them to use the environment variables in different modes. 

---
<table>
<tr>
<td>
<center><a href="https://discord.gg/bGmS2tE"><img src="https://images.hive.blog/DQmdthy4q4vyefBYmjMJtx7qHBmLnCfP2btiRPhRyc2U8hP/Indiaunited.png"/></a></center>
</td>
<td>
<center><a href="https://kanibot.com/"><img src="https://images.hive.blog/DQmdm8hKPz9TZL8Gd8bPyeVHm9hfgMqqiHcKL8283RBv2eH/Kanibot.png"/></a></center>
</td>
<td>
<center><a href="https://netbox.global/r/balanbx"><img src="https://images.hive.blog/DQma1a9t6rceDQYvMt6FhNkHuUUjAkQssZHrLJcXKfiQBFd/NetboxGlobal.png"/></a></center>
</td>
<tr>
<td>
<center><a href="https://r.honeygain.me/BALA4F8CD5"><img src="https://images.hive.blog/DQmdCZg8z6sxVukSdPm2kXRAhhnySqPZqK9YQ5hco65sp4n/Honeygain.png"/></a></center>
</td>
<td>
<center><a href="https://www.privex.io/?r=bala41288"><img src="https://images.hive.blog/DQmPB85eAMrQNGV7C4ykbfVTDNaiGmb8PfuiFr2AL8N8JQm/Privex.png"/></a></center>
</td>
<td>
<center><a href="https://www.publish0x.com/?a=YRdG6knybD"><img src="https://images.hive.blog/DQmcb3f3oJvjyxyScbim4gKPAnrHTyXjYtwk7HeC9aTN9Pn/Publish0x.png"/></a></center>
</td>
</tr>
</tr>
</table>

---

Posted with [STEMGeeks](https://stemgeeks.net)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 171 others
properties (23)
authorbala41288
permlinksteps-to-use-env-files-in-your-quasar-framework-project
categoryhive-163521
json_metadata{"tags":["quasar","stem","neoxian","palnet","vue","development","coding","javascript","ash","archon"],"image":["https://images.hive.blog/DQmQh5wMyJSKadv5MYg4WN3r5xKG2suL51NgSiaDB4bs3x7/image.png","https://images.hive.blog/DQmRe8wVE5wgVTMuNU5ZADbMgJZGT5cXTtyrZxn48HqyWqm/image.png","https://images.hive.blog/DQmdthy4q4vyefBYmjMJtx7qHBmLnCfP2btiRPhRyc2U8hP/Indiaunited.png","https://images.hive.blog/DQmdm8hKPz9TZL8Gd8bPyeVHm9hfgMqqiHcKL8283RBv2eH/Kanibot.png","https://images.hive.blog/DQma1a9t6rceDQYvMt6FhNkHuUUjAkQssZHrLJcXKfiQBFd/NetboxGlobal.png","https://images.hive.blog/DQmdCZg8z6sxVukSdPm2kXRAhhnySqPZqK9YQ5hco65sp4n/Honeygain.png","https://images.hive.blog/DQmPB85eAMrQNGV7C4ykbfVTDNaiGmb8PfuiFr2AL8N8JQm/Privex.png","https://images.hive.blog/DQmcb3f3oJvjyxyScbim4gKPAnrHTyXjYtwk7HeC9aTN9Pn/Publish0x.png"],"links":["https://discord.gg/bGmS2tE"],"app":"stemgeeks/0.1","format":"markdown","canonical_url":"https://stemgeeks.net/@bala41288/steps-to-use-env-files-in-your-quasar-framework-project"}
created2021-08-06 15:32:45
last_update2021-08-06 15:32:45
depth0
children6
last_payout2021-08-13 15:32:45
cashout_time1969-12-31 23:59:59
total_payout_value3.142 HBD
curator_payout_value3.089 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,915
author_reputation1,512,707,149,500,858
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,362,138
net_rshares8,935,184,688,990
author_curate_reward""
vote details (235)
@alokkumar121 ·
This is too technical for me and even after trying to understand for some time, I got nothing. Wish someday I can learn more about technology.
👍  ,
properties (23)
authoralokkumar121
permlinkqxgohu
categoryhive-163521
json_metadata{"tags":["stem"],"app":"stemgeeks/0.1","canonical_url":"https://stemgeeks.net/@alokkumar121/qxgohu"}
created2021-08-07 08:49:00
last_update2021-08-07 08:49:00
depth1
children2
last_payout2021-08-14 08:49:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length142
author_reputation2,489,687,536,878,055
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,377,687
net_rshares1,270,876,529
author_curate_reward""
vote details (2)
@bala41288 ·
Lol yeah sorry about that. Cheers! ! 
properties (22)
authorbala41288
permlinkre-alokkumar121-202189t8516589z
categoryhive-163521
json_metadata{"tags":["hive-163521","stem"],"app":"ecency/3.0.20-mobile","format":"markdown+html"}
created2021-08-09 02:35:18
last_update2021-08-09 02:35:18
depth2
children1
last_payout2021-08-16 02:35:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length37
author_reputation1,512,707,149,500,858
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,412,244
net_rshares0
@alokkumar121 ·
😀🙏
properties (22)
authoralokkumar121
permlinkre-bala41288-qxjwrh
categoryhive-163521
json_metadata{"tags":["hive-163521"],"app":"peakd/2021.07.5"}
created2021-08-09 02:40:30
last_update2021-08-09 02:40:30
depth3
children0
last_payout2021-08-16 02:40:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2
author_reputation2,489,687,536,878,055
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,412,306
net_rshares0
@poshtoken ·
https://twitter.com/jlufer/status/1423677674501857285
<sub> The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
properties (22)
authorposhtoken
permlinkre-bala41288-steps-to-use-env-files-in-your-quasar-framework-pr-4218
categoryhive-163521
json_metadata"{"app":"Poshtoken 0.0.1"}"
created2021-08-06 16:16:09
last_update2021-08-06 16:16:09
depth1
children0
last_payout2021-08-13 16:16:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length241
author_reputation5,176,989,871,534,246
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id105,362,760
net_rshares0
@xawi ·
beyond my understanding level :P XD
properties (22)
authorxawi
permlinkqxflyk
categoryhive-163521
json_metadata{"app":"hiveblog/0.1"}
created2021-08-06 18:56:51
last_update2021-08-06 18:56:51
depth1
children1
last_payout2021-08-13 18:56:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length35
author_reputation463,747,998,385,883
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,365,162
net_rshares0
@bala41288 ·
Lol it's okay. Some things are always like that. 😀
properties (22)
authorbala41288
permlinkre-xawi-202189t8647234z
categoryhive-163521
json_metadata{"tags":["ecency"],"app":"ecency/3.0.20-mobile","format":"markdown+html"}
created2021-08-09 02:36:48
last_update2021-08-09 02:36:48
depth2
children0
last_payout2021-08-16 02:36:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length50
author_reputation1,512,707,149,500,858
root_title"Steps to use .env files in your Quasar framework project"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,412,267
net_rshares0