How to use dotenv with Vue.js

If your project was create by using Vue CLI 3, no need to use dotenv to get environment variables.

To get environment variables within .env file in your project:

  1. Placing the .env file in your project root.
  2. In the .env file, specifying environment variables with “VUE_APP_” prefix.

    VUE_APP_SOMEKEY=SOME_KEY_VALUE.

  3. Finally, you can access them with process.env.* in your application code.

    console.log(process.env.VUE_APP_SOMEKEY) // SOME_KEY_VALUE

Referance: Vue CLI 3 – Environment Variables and Modes

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)