@postnord/pretty-env
v0.0.8
Published
Easily handle env vars
Downloads
874
Maintainers
Keywords
Readme
Introduction
This module gives you a nice interface to handle environment variables.
Quick start
import envService from '@postnord/pretty-env'
// in batch
const { API_BASE_URL, NODE_URL } = envService.requireEnvs({ envs: ['API_BASE_URL', 'NODE_URL'] }) // returned envs are typed as string, so no more process.env.NODE_URL as string
// single env var fetch
const myEnv = envService.requireSingleEnv({ env: 'mySingleEnv' })
// When the env does not exist
envService.requireSingleEnv({ env: 'myNonExistingEnv' }) // throws "Environment variable myNonExistingEnv is missing"
// If you want to parse and validate the value
envService.requireSingleEnv<Array<string>>({
env,
parser: JSON.parse,
validateValue: {
validationFunction: Array.isArray,
errorMessage: 'Should be an array but is not',
}
})