N
Nuxt6mo ago
typeshit

env How can i use env variables in a .js file ?

can someone help me?
No description
No description
13 Replies
pyplacca
pyplacca6mo ago
Prefix the variables with VITE_ and access them via import.meta.env
typeshit
typeshitOP6mo ago
ty
manniL
manniL6mo ago
this won't work when trying to change them at runtime, just FYI I'd suggest passing the runtimeConfig part in there when using the JS file
handshake
handshake6mo ago
.env <NUXT_SOME_NAME>=someValue nuxt.config.ts runtimeConfig: { public: { <someName>: import.meta.env.NUXT_SOME_NAME}} and then in your code use some.vue const config = useRuntimeConfig(); const theThing = config.public.<someName> if you don't want them public, put the env value top level of "runtimeConfig" (e.g. outside of public)
manniL
manniL6mo ago
You can even leave the right hand side of the runtimeConfig value empty
manniL
manniL6mo ago
Alexander Lichter
YouTube
Nuxt's runtimeConfig - The most common mistake
🤯 Throughout my projects, consultancies and code reviews I came across lots of interesting findings - also with regards to Nuxt's runtimeConfig feature. Repeatedly I noticed ONE big mistake though which you might do at this very moment in your project. In this video, explain what it is, why you shouldn't do it and how to use runtimeConfig correc...
typeshit
typeshitOP6mo ago
are u telling me to do this?
No description
typeshit
typeshitOP6mo ago
No description
typeshit
typeshitOP6mo ago
No description
typeshit
typeshitOP6mo ago
this is the only way?
manniL
manniL6mo ago
I'd just pass the two values to the function
manniL
manniL6mo ago
but besides that, yes. You might be easier off using https://github.com/nuxt-modules/supabase though
GitHub
GitHub - nuxt-modules/supabase: Supabase module for Nuxt.
Supabase module for Nuxt. Contribute to nuxt-modules/supabase development by creating an account on GitHub.
typeshit
typeshitOP6mo ago
whats that?
Want results from more Discord servers?
Add your server