In my sveltekit app, I keep doing this in my +server.js
files throughout my routes:
import config from '$lib/server/config.js';
where the exported config object contains database connection details, etc. (some of which in turn come from environment variables), and this information is adapted to the environment I am running in (dev, prod, etc.).
I have two questions about this. First, is there a canonical place to put such a config.js
file other than where I am putting it?
Second, is there a way to load this config object globally so I don't need to load it repeatedly in every +server.js
file that needs this information? I could put it all in environment variables (via .env
, for example), but then I lose some of the conveniences of my config.js
.