Home

Issue: 1323

How do I access environment variables in a component?

[issue link]

I can’t find a way to access environment variables (especially within a component). I created a brand new project with:

vue init nuxt/starter new-project
cd new-project
npm install
npm run dev

nuxt.config.js

module.exports = {
  ...
  env: {
    hey: 'hey'
  }
}

pages/index.vue

<script>
import Logo from '~/components/Logo.vue'

export default {
  components: {
    Logo
  },

  mounted () {
    console.log(process.env)
  }
}
</script>

console.log() prints an empty object. I read in the documentation that you could access environment variables with process.env. What am I doing wrong? 😃

I am using the latest version of nuxt.js (nuxt@1.0.0-rc3) and my version of node is 8.2.1.

This question is available on Nuxt.js community (#c1172)