#useRuntimeConfig vs process.env in api routes
1 messages · Page 1 of 1 (latest)
Yes. Always rely on runtimeConfig
See also
https://youtu.be/_FYV5WfiWvs
🤯 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...
in the video, you're using $config in a template and using process.env in the nuxt.config public runtime configuration. You show that the only way to actually change the public variable 'myValue' during runtime, is by defining 'NUXT_PUBLIC_MY_VALUE'
so from what I've understood, by using process.env directly in an api route, i won't have the ability to change the value during runtime, since the NUXT_MY_VALUE property wouldn't even be available due to not using runtimeConfig/useRuntimeConfig()/$config in the first place, is that correct?
correct. You should always use runtimeConfig so you can actually change the values during runtime (hence the name) 👍
thank you! 🙂
Hello Alex! Love your videos, following since the first video.
I have this type of question.
I am not using ssr but i want to use private key. Is it safe to use public runtime config variable? Or this is wrong?
Thank you so much 🙏🏻
Really happy to hear that 😊
When using no SSR, all keys are public. I’d suggest to either use a separate nitro instance for an API you can call or do that in the same project. That means you need a server running though
So its not safe... Hmm.. Does it mean I should worry about it?
Does Nuxt protect these api keys with some salt in JS after build?
Appreciate your help to community! Means a lot!
If the key should not be exposed (think of stripes Private key) then yes, that’s something to worry about 👀
There is no protection as it wouldn’t help. You could just place a debugger and check when the key is used
now i won't be able to sleep

Sorry 🙈
What kind of key is it if I may ask?
Like, which service
a discord bot key
Oh yeah, set up an API + reroll the key👌🏻
Thank you! 💪
Waiting for new videos