A tiny environment variables manager. Powered by AWS SSM/Parameter Store.
npm install @handstudio/envman
`` _ \ / _
__ _ ____ ___ __ ___ __ _ _ __ _ __
/ _ \ '_ \ \ / / '_ | '_ \`
| __/ | | \ V /| | | | | | (_| | | | |
\___|_| |_|\_/ |_| |_| |_|\__,_|_| |_|
is hosted in a private NPM repository, so make sure you have access to handstudio's private repo. check out your $HOME/.npmrc file.
`bash
@handstudio:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=GITHUB_TOKEN
`
$3
`bash
npm install --save @handstudio/envman
`
$3
`bash
npm install -g @handstudio/envman
`Usages
$3
Prints a list of all environment variable keys.
`bash
envman keys
envman keys
`$3
Assume that there are stored environment variables in AWS ParameterStore. you can env-variables like followings:
`bash
envman print --key
envman print \
--key /NCDinos/BatchWorker/Stage \ --output json \
--profile someAwsProfileName
`
The --output flag can be one of json, dotenv, ebextensions.
It is also possible to read environment variables from multiple keys.
`bash
envman print --key --key
envman print \
--key /NCDinos/BatchWorker/Stage \
--key /NCDinos/Common/Stage \ --output json \
--profile someAwsProfileName
`If you're using
AWS STS with MFA(Multi Factor Authorization), use --use-mfa flag.
`bash
envman print \
--key /Test/Stage \
--use-mfa
`$3
Parameter can be saved in environment variable storage through --env: KEY VALUE command.
`bash
envman save --env:K1 V1 --env:K2 V2 ...
envman save /NCDinos/Common \
--env:MASTER_KEY somemasterkey \
--env:IV someiv \
--profile ncdinos
`
Suppose that the environment variables are stored in the form of a
dotenv file locally. You can store it in a remote environment variable repository as follows:
`bash
envman save --input [dotenv | json] --path
envman save /NCDinos/Common \
--input dotenv \
--path $HOME/test-env.env \
--profile ncdinos
`
The --input flag can have the following values: json, dotenvUsage with node.js projects
$3
`bash
env \
$(envman print \
--key /ncdinos/auction-mall/stage \
--profile ncdinos \
) node app.js
`
Of course, you can also use ENVMAN as a npm script as follows. The following sample package.json shows that using ENVMAN and node.js project together.
`json
{
"name": "env-test",
"version": "1.0.0",
"description": "envman test project",
"main": "app.js",
"scripts": {
"start": "env $(envman print --key /ncdinos/auction-mall/stage --profile ncdinos) node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {},
"devDependencies": {
"@handstudio/envman": "^1.0.1"
}
}
`$3
You can use the following method inspired by dotenv.
`bash
ENVMAN_KEY=/NCDinos/Common \
node -r @handstudio/envman/config yourApp.js
`
By using ENVMAN_KEY, you can specify the key of the environment variable you want to load. If you need a separate AWS profile name, you can use it as follows by using ENVMAN_AWS_PROFILE :
`bash
ENVMAN_KEY=/NCDinos/Common \
ENVMAN_AWS_PROFILE=ncdinos \ # your AWS profile name
node -r @handstudio/envman/config yourApp.js
`
Loading environment variables is basically an asynchronous operation. for this reason, it is necessary to use a slightly tricky method to use it with the --require flag of node.js. check out following example:
`javascript
const { waitUntilLoaded } = require('@handstudio/envman');// Your App Entrypoint
(async () => {
console.log('Waiting for envman ...');
await waitUntilLoaded(); // waits until ENVMAN loading complete
console.log('App started!');
console.log(process.env); // At this moment, ENVMAN will be finished loading all environment variables.
})();
`Function references
$3
Loads the environment variables from remote store.
returns Promise