Skip to content

A lightweight package for using cStore configs in JavaScript

Notifications You must be signed in to change notification settings

shivpatel/cstore-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cStore for JavaScript

NPM

cstore-js is a lightweight JavaScript package for using cStore configs in Node. It currently supports the cStore S3 and SSM Parameter Store storage methods. It can automatically inject your configs into Node's process.env and decrypt env vars encrypted in Secrets Manager with references written in the {{ENV/KEY}} syntax.

This module is only intended for use alongside an existing cStore setup.

Tested against cStore 3.3.1.

Installation

Important: To minimize package size, cstore-js only includes the aws-sdk package as a dev dependency. You must have the aws-sdk available in your project when creating a production-ready build. AWS Lambda function code is immune from this requirement as the aws-sdk is provided for you in the Lambda Node runtime.

npm

npm install cstore-js --save

yarn

yarn add cstore-js

Usage

Pull Existing Configs

const cstore = require('cstore-js');

const initApp = async () => {
  
  const tag = process.env.NODE_ENV;
  const configs = await cstore.pull(tag);
  
  // Connect to DB
  // Start express.js, etc.
  
}

init();

API

pull (tag: String, ymlPath: String, injectIntoProcess: Boolean, injectSecrets: Boolean)

Locates the given tag in the cstore.yml file. Fetches the specified configs via AWS SDK and returns an object with env vars as key/value pairs. Also injects the variables into Node's process.env by default.

Params:

  • tag (required) - a valid tag associated to the env you're pulling configs for.
  • ymlPath (default: process.cwd()/cstore.yml) - Absolute path to your cstore.yml file.
  • injectIntoProcess (default: true) - if true, pulled configs will automatically be injected into Node's process.env.
  • injectSecrets (default: true) - if true, env vars referencing secrets manager will be fetched and returned in decrypted form.

About

A lightweight package for using cStore configs in JavaScript

Resources

Stars

Watchers

Forks

Packages

No packages published