How to use linux variables in .env of vue.js?


by aubrey , in category: Javascript , 8 months ago

How to use linux variables in .env of vue.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by rollin , 8 months ago


To use Linux variables in the .env file of Vue.js, you can follow these steps:

  1. Create a .env file in the root directory of your Vue.js project.
  2. Open the .env file and define your Linux variable with the VARIABLE_NAME=value syntax. For example: VUE_APP_API_KEY=myapikey123.
  3. In your Vue.js project, add the following code to access the Linux variable from the .env file:
const apiKey = process.env.VUE_APP_API_KEY;

You can then use the apiKey variable in your Vue components.


  • The prefix VUE_APP_ is necessary in the variable name to make it accessible in Vue.js.
  • Make sure to restart the development server after making changes to the .env file for them to take effect.