question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `useEnvVars()` in Qwik

See original GitHub issue

Is 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:closed
  • Created a year ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
elyobocommented, Dec 9, 2022

Has this been documented somewhere? I can’t find relevant docs on the site.

image

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.

1reaction
youngboycommented, Aug 26, 2022

@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

useClientEffect$(() => {
  const env = import.meta.env
})

will resulting every env key & value exposed to JS source code in client

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found