Reputation: 194
I'm trying to add environment variables to the nuxt.config.js
file in the env
property to access the variables in server/index.js
file but it gives undefined
. According to the env documentation, the variables should work in both client and sever. Not sure if i'm missing something? Thanks in advance.
module.exports = {
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000'
}
}
Upvotes: 2
Views: 2915
Reputation: 1984
All env variables in Nuxt.js must start with NUXT_ENV
.
In vue.js it must start with 'VUE_APP'
Upvotes: 4
Reputation: 57
I know it's quite a late answer but just came across the same issue and thought my findings might help to some future mate in trouble.
It was as simple as include the require('dotenv').config()
before any process.env.XXX
reference.
Note that you might have better solution if using nuxt 2.13+.
Upvotes: 0