You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a few suggestions to make this a helpful library for more users. The way we use envalid along Fastify is where we decorate a variable called config (or similar) with the result of cleanEnv. This produces a easy way to get configuration value. Typically we have one configuration file (config.ts). It looks something like this:
import{cleanEnv,str}from'envalid';// In reality, we also add a custom middleware here 👇exportconstconfig=cleanEnv(process.env,{HELLO_WORLD: str({devDefault: 'something'}),});exporttypeConfig=typeofconfig;
Along with this, we add the Config type to a global type definition file as such:
I imagine fastifyEnv (or another name) could come prebuilt with custom middleware and wired with environment variables (potentially changed with the fastify.register function).
I think we can wire the types somehow here so they're available just by registering the plugin. Not sure, I haven't played around with it yet. Regardless, what do you think?
The text was updated successfully, but these errors were encountered:
simenandre
changed the title
Refactor suggestion
Improving developer experience for Fastify + Envalid users
Apr 4, 2023
Hello 👋
Thank you for this library!
I have a few suggestions to make this a helpful library for more users. The way we use
envalid
along Fastify is where we decorate a variable calledconfig
(or similar) with the result ofcleanEnv
. This produces a easy way to get configuration value. Typically we have one configuration file (config.ts
). It looks something like this:Along with this, we add the
Config
type to a global type definition file as such:And lastly, in our
server.ts
file, you'll typically see:I haven't tried, but I think we can wrap some (or all) of this in a Fastify plugin for a better developer experience. I imagine something like this:
In our
config.ts
file:I imagine
fastifyEnv
(or another name) could come prebuilt with custom middleware and wired with environment variables (potentially changed with thefastify.register
function).Moving on to the
server.ts
file:I think we can wire the types somehow here so they're available just by registering the plugin. Not sure, I haven't played around with it yet. Regardless, what do you think?
The text was updated successfully, but these errors were encountered: