Access environment variables from `store` or `root` folder
I have a
.ts
file where I would like to read values from my environment variables but anytime I do so, I get undefined. How can I go around this and access env variables from anywhere in my project?4 Replies
Consider using runtime config without leaking sensitive data.
Right, I read about it here (https://nuxt.com/docs/guide/going-further/runtime-config) and it still doesn't look like I'll be able to just use
process.env.VAR_NAME
. I'd love to be able to just do that, alternatively I can refactor my code.
This is file the store/auth.ts
:
Maybe this is not the right location for itNuxt
Runtime Config · Nuxt Advanced
Nuxt provides a runtime config API to expose configuration within your application.
What do you mean by “I won’t be able to use env vars” with runtime config? The purpose of runtime config working in tandem with env vars is that they are evaluated in the config and passed through to the app therefore not required to use
process.env
within your app.My idea was to use env variables within certain folders but I guess that's not possible all the time. So, I ended up re-factoring my code to follow what Nuxt reccommends.