1.0.3 • Published 3 years ago

@technician/env-config-source v1.0.3

Weekly downloads
32
License
Apache-2.0
Repository
github
Last release
3 years ago

@technician/env-config-source

npm version npm downloads npm license

dependencies Build Status GitKraken

A config source for accessing environment variables.

This package provides the EnvConfigSource for use with the Technician config manager.

Technician

Installation

npm i @technician/env-config-source

This package is compatible with Node 10 LTS and up.

Usage Examples

The Basics

import {Technician, DefaultInterpreters} from 'technician';
import {EnvConfigSource} from '@technician/env-config-source'

const technician = new Technician(DefaultInterpreters.asText('utf8'));
technician.addSource(new EnvConfigSource());

await technician.read('MY_ENV_VAR');

Overriding Another Source With Environment Variables

import {Technician, DefaultInterpreters} from 'technician';
import {EnvConfigSource} from '@technician/env-config-source';
import {FSConfigSource} from '@technician/fs-config-source';

const technician = new Technician(DefaultInterperters.asBuffer(), {
    // Higher priority sources are checked, even if a value is cached.
    cacheRespectsPriority: true,
    // Set a default cache length. By default, the cache lasts forever.
    defaultCacheLength: 1000 * 60 * 60;
});
const envSource = new EnvConfigSource();
const filesystemSource = new FSConfigSource('/etc/ssl/certs');

// Sources with higher priority will be used over those with lower priority.
// By default, sources have a priority of 0 and cache forever.
technician.addSource([
    {
        source: envSource,
        priority: 1,
        cacheFor: -1 // Disable caching for envSource
    },
    filesystemSource // Just use the default config for FS.
]);

// Create an alias that links both config sources to a single key.
technician.alias('ssl_cert', ['SSL_CERT', 'mysite.crt']);

// This alias will return the filesystem value and cache it for an hour --
// unless SSL_CERT is set, which overrides it and disables caching.
const value = await technician.read('ssl_cert');

Contributions

Contributions and pull requests are always welcome. Please be sure your code passes all existing tests and linting.

Pull requests with full code coverage are strongly encouraged.

License

Apache-2.0