4 comments

[ 2.7 ms ] story [ 17.4 ms ] thread
How is this different from dotenv ?
I'm also having trouble figuring out what it does. Is it only for certain services?
dotenv allows you to store env values in the .env file. envconfig handles normalizing the various ENV values from providers into a single configuration. Every provider has a different env value, such as POSTMARK_SMTP_SERVER, or SENDGRID_SMTP_SERVER. envconfig knows about these and provides a single service agnostic interface to that information.

.env and envconfig work very well together.

dotenv reads a file into Ruby's ENV.

envconfig reads Ruby's ENV and exposes it as a useful configuration object. envconfig-rails uses that to e.g. push the SMTP settings into ActionMailer.

The key value, though, is that envconfig knows about Heroku and Broadstack add-on ENV names.

e.g. when you add the MemCachier Addon, it simply puts MEMCACHIER_SERVERS, MEMCACHIER_USERNAME, MEMCACHIER_PASSWORD into your ENV. Envconfig knows those var names, and assigns them to the memcached service.

If you looks at the various provider mappings in e.g. https://github.com/broadstack/envconfig/blob/master/lib/envc... you'll see that it knows about ENV-provided, and static, configuration for each provider.