diff --git a/README.md b/README.md index 4d221f3..b749488 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,14 @@ env.assert( ); ``` +#### Adding to the environment + +```javascript +env.set('NEW_ENV_VAR', 'newVal'); +process.env.NEW_ENV_VAR // 'newVal' +env.get('NEW_ENV_VAR'); // 'newVal' +``` + ### AWS Credentials ```javascript diff --git a/package.json b/package.json index d7ce904..26023df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "good-env", - "version": "7.5.0", + "version": "7.6.0", "description": "Better environment variable handling for Twelve-Factor node apps", "main": "src/index.js", "scripts": { diff --git a/src/index.d.ts b/src/index.d.ts index b4401a4..a4760c1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,5 @@ declare module "good-env" { + export const set: (key: string, value: string) => void; /** * @description Tell Good Env to go to secrets manager, grab the object under the specified secretId and merge it with the * environment. diff --git a/src/index.js b/src/index.js index 204d4f4..7127e86 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,10 @@ let store = { ...process.env }; module.exports = Object .create({ + set (key, value) { + process.env[key] = value; + store[key] = value; + }, async use (awsSecretsManager, secretId) { const { SecretsManagerClient, GetSecretValueCommand } = awsSecretsManager; const client = new SecretsManagerClient({ diff --git a/test/test.js b/test/test.js index 4905244..9aff442 100644 --- a/test/test.js +++ b/test/test.js @@ -9,6 +9,13 @@ const { SecretsManagerClientHappy } = require('./mocks'); +test('it adds an env var', (t) => { + env.set('NEW_ENV_VAR', 'bar'); + t.equals(process.env.NEW_ENV_VAR, 'bar'); + t.equals(env.get('NEW_ENV_VAR'), 'bar'); + t.end(); +}); + test('it throws when no secretId is given when attempting to use secretsManager', async (t) => { const awsSecretsManager = { SecretsManagerClient: SecretsManagerClientHappy, GetSecretValueCommand };