@sophya/envy v1.1.1
Envy
A Sophya npm package and CLI for managing .env key/values for local development, CI, and CD workflows
Usage
Pulling Keys
In order to pull keys down for a particular environment (local, staging, or prod), FIRST, make sure there is a .env.required file in the directory you are running the script from The .env.required requirements file is a file that specifies which keys in our AWS Param Store you actually need. This file should be service specific. For instance, node-app needs the slack keys, but gaia-server does not. The requirements file should look like this (note the newline at the end of the file):
KEY_1
KEY_2Next, run the script:
pull-env <env> <outputFile>You will be prompted to sign in with amazon. When you configure your aws profile on the initial run, PLEASE set your profile name to
default.
If all goes well, the end result should be a file written to .env with contents like
KEY_1=VALUE_1
KEY_2=VALUE_2Loading configuration
This library also supports loading, parsing and typing configuration data from the appropriate .env file for the current environment:
import { load } from '@sophya/envy';
// Declare a type for the configuration we want to load
type Configuration = {
host: string
port: number
verbose: boolean
};
// Load ENV from both the process ENV and the correct .env file for the current environment
const config = load<Configuration>((env, config) => {
config.host = env.HOST;
config.port = Number(env.PORT);
config.verbose = (env.VERBOSE ?? '').toLowerCase() === 'true'; // Boolean('false') === true lol
return config;
});
// `config` is now typed and structured
console.dir(config);