@pdenya @Franky47 this morning I started to refactor to pass the config as a variable, and for some modules the pattern works well (if I have an initialiser/constructor function), but for others the entire module is expected to be initialised at run time. So to avoid adding an init function to those modules, I’ll probably leave some as imports.

I’ll open source this product in a few weeks, hopefully!

1
Share
Share on Mastodon
Share on Twitter
Share on Facebook
Share on Linkedin
François Best

@paul @pdenya I've encountered a similar use-case when loading environment variables, validating them and exposing the result to the rest of the application.

Here's how I go about doing it, using Zod for parsing and transforming, and crashing early with helpful messages if something isn't right.

github.com/SocialGouv/e2esdk/b

Though the resulting env object is exported/imported rather than passed as arguments, in Fastify I could expose it as a server property and use that as dependency injection.

0
1y
Replies