Environment Variables in SvelteKit and Adapter-Node

Tingnoy
Jan 27, 2022

--

Our topic for today is “How to change env config without rebuild app?”.

  1. Create .env file in root project
.env file

2. Set config in svelte.config.js

add vite config to define global variable

3. Convert your environment to constant

convert from env to constant variable

4. Install env-cmd to load .env file to environment variable

npm install env-cmd

5. use env-cmd

use env-cmd to load env config

Conclusion

You can try to build app and run with env-cmd node build/index.js process.env.XXX should be work. Now you can change config in .env file and restart app without rebuild app.

--

--

No responses yet