Environment variables in Quasar
Posted on
by Kevin FoongMake sure you keep any sensitive information in environment variables such as database passwords and API keys. In Vue you can use the dotenv
package and in Quasar you can use the quasar-dotenv
package which is wrapper around dotenv
.
cd to your project folder and install quasar-dotenv
npm install quasar-dotenv
Now create a .env
file in your project root and add any variables. For example:
OW_API_KEY = '002db37bfc6be228c33d416df8a6e917'
GM_API_KEY = 'CIzaTyDL6C63jOmI2KCbysrmRSJ_2DriHfFMqZY'
In Quasar you can now access your variables via process.env
process.env.OW_API_KEY
process.env.GM_API_KEY
In your .gitignore
add .env
to ensure it is not pushed to Github.
Also create a .env.example
file in your root folder which is a skeleton file, to give other users an idea of the variables required.
OW_API_KEY =
GM_API_KEY =
That's it!
Tags: quasar