Closed lirantal closed 1 year ago
Could you split creation of the Fastify application with the call to listen in two files, as this enables testing without using globals?
Sure thing. I was going for simplicity there but have merged a PR to change that to a more modular structure: https://github.com/lirantal/fastify-dotenv-envschema-example/pull/1 (landed in main
already)
It's a good question and I was asking myself the same thing but I thought the ideal place is here because folks using the @fastify/env
plugin would probably already know best practices and how to use it, yet new folks landing on this repository might look for how to get started and how they can use env-schema
, especially since it doesn't have anything to do with Fastify as the app framework itself, but just happens to live on this org.
So, I'd keep it here to be more helpful but happy to move elsewhere if you think it'd be a better fit.
I personally find env-schema better and I don't use fastify-env ;).
fastify-env is pretty small and is anyway just a wrapper around env-schema though, isn't it? I figured if you don't use fastify-env you probably just do the same plugging wrapping yourself.
I tend to not wrap this into a plugin, but rather read it before Fastify is started. In this way I can customize the options of Fastify itself
I tend to not wrap this into a plugin, but rather read it before Fastify is started. In this way I can customize the options of Fastify itself
Agreed. I really don't understand the point of fastify-env
.
'use strict'
const dotenv = require('dotenv')
const config = dotenv.config()
const fastify = require('fastify')({ /* use stuff from config */})
fastify.decorate('env', {
getter() { return config }
})
Adding a section to list helpful resource guides to get started with building with env-schema
Fixes #142
Checklist
npm run test
andnpm run benchmark