DEV Community

Discussion on: Using environment variables in SvelteKit (and Vite)

Collapse
esojrafael profile image
Jose Rafael

Thanks for the post! Quick question, why would I declare any other variable besides VITE_* if I cant access it in endpoints. What if I have sensitive credentials that I need in an endpoint.

Collapse
danawoodman profile image
Dana Woodman Author

Great question, I don't know the reason Vite went this way ultimately, but I would assume you could have sensitive variables in .env and then import them where you need using dotenv or similar. Since Vite isn't designed for Svelte, it likely doesn't know if it is running in an endpoint vs a component, so I think that may be the root cause. Maybe you can prefix your private vars in a way so you don't accidentally like vars, like VITE_PRIVATE_SOME_SECRET_TOKEN?

Collapse
barmaleyhd profile image
Dmitry Nagorny

Same questions I had when just learned VITE_ concept. I'm not alone :)