Support `useEnvVars()` in Qwik
See original GitHub issueIs your feature request related to a problem?
It would be nice if environment variables could be supported in Qwik. Something similar to Next.js
Describe the solution you’d like
Pseudocode of what I have in mind.
function useEnvVars(): Record<string, string> {
return useStore(process.env):
}
NOTE:
- The above code needs to be more complicated as multiple calls to
useEnvVars
need to return the same instance
Describe alternatives you’ve considered
n/a
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:17 (16 by maintainers)
Top Results From Across the Web
Using environment variables in SvelteKit (and Vite)
UPDATE August 8, 2022: SvelteKit now has support for both private and public environment variables without directly using Vite, ...
Read more >Don't use environment variables for configuration | Hacker News
A real example would be a service provider which a developer would understand to have the sole purpose of pulling from environment or...
Read more >What are Environment Variables in Rails? - Dev Genius
I had read on some quick google searches that environment variables exist within the local system and are available across all applications.
Read more >Darragh ORiordan: I help you build awesome web ...
Hi! I'm Darragh ORiordan. I live and work in Sydney, Australia building and supporting happy teams that create high quality software for the...
Read more >Support `useEnvVars()` in Qwik - PullAnswer
This is probably not the best solution as not all hosting platforms are Node environments. However, Qwik already has a useEnvData() hook that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Has this been documented somewhere? I can’t find relevant docs on the site.
I also note that https://github.com/BuilderIO/qwik/issues/2138#issuecomment-1331981554 suggests more recently that
useEnvData
is a low level API that qwikcity developers should never have to use, but getting secrets from the server env sounds like an absolutely normal requirement that has to be done all the time - having some clarity about the recommended approach here would be great!Vite env vars are presumably only available at dev / compilation time, not at run time, so fills a related but not quite the same niche as accessing run time environment variables.
While the decision not to support this seems to have been made, I note that SvelteKit seems to have a well thought out set of options here that distinguish between public/private and dynamic/static, so if this is revisited it might be worth looking at too.
@nnelgxorz Really helpful explanation, would be great if add it to document.
And perhaps need forewarn about usage of causing leaky credentials ENV issues. In SSR mode, Vite env is convenient and accessible everywhere, https://github.com/vitejs/vite/pull/5404
like
will resulting every env key & value exposed to JS source code in client