npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@windingtree/config-profiles

v1.0.11

Published

Downloads

4

Readme

About

This package allows developers to:

  • use various configuration profiles (e.g. production, staging, development, unit-test, integration-test)
  • activate profile and retrieve configuration properties for a given profile
  • store and retrieve configuration properties from database (mongoDb collection) at runtime/development
  • maintain all profiles and it's values in source code repository (so that no configuration entry is lost while branching/development cycle)

Installation

npm i @windingtree/config-profiles

Usage

###Generate local file with configuration from database In order to avoid using async/promises each time you need to retrieve configuration entry from collection, at start/build time local JSON file needs to be generated. Below snippet will generate such a file which can be later loaded to retrieve configuration values.

//Initialize - bare minimum is to provide URI to mongo database which stores configuration 
const profiles = require('../src/profiles').init({dbUrl:process.env.MONGO_URI});
//generate local JSON file with 'staging' profile
profiles.dumpProfile('staging')

It's possible to customize it by providing various init parameters

//Initialize - bare minimum is to provide URI to mongo database which stores configuration 
const profiles = require('../src/profiles').init({ 
    dbUrl:process.env.MONGO_URI, 
    baseFolder: '/profiles',      //folder where local JSON file should be generated to
    profilesCollectionName:'profiles', //name of the collection in the database which stores our configuration,
    activeProfileEnvVariableName:'ACTIVE_PROFILE', //name of environment variable which stores the name of the current profile (e.g. staging, production)
    encryptionDetails:'aes-256-ctr:1234567890123:ff7dc996632d5ea672a7acd5776f2ff5'  //key to encrypt/decrypt configuration entires
  }
  );
//generate local JSON file with 'staging' profile
profiles.dumpProfile('staging')

###Retrieve value of configuration entry for a given profile

In order to retrieve configuration entry use below snippet. It will: a) load local JSON file for 'staging' profile b) find and return value of 'example_configuration_key' configuration entry c) decrypt it if it was encrypted

const profiles = require('../src/profiles').init({dbUrl:process.env.MONGO_URI});
let keyValue = profiles.getProfileEntry('staging', 'example_configuration_key');

If you need to have the possibility to also override configuration entries using environment variables, use the below snippet

Below code will: a) Determine what's the current profile (based on environment variable) b) load local JSON file for that profile c) find and return value of 'example_configuration_key' configuration entry d) decrypt it if it was encrypted e) if there is environment variable 'example_configuration_key' defined - it will use that (env variable has higher priority over value from local JSON file) f) if neither (env or JSON) keys are found - default value will be returned

const profiles = require('../src/profiles').init({dbUrl:process.env.MONGO_URI});
let keyValue = profiles.getEnvOrProfileEntry('example_configuration_key','DEFAULT_VALUE');

CLI

There is also a CLI available which allows manipulation of the configuration/profiles from command line prompts. To execute this - use below snippet.

const profiles = require('../src/profiles');
profiles.executeCLI();

CLI is used to initialize/update configuration profiles from command line. CLI requires additional arguments to be provided, depending on a task you want to execute. See below usage.


This script is used to:
-initialize(restore) configuration in database based on configuration from JSON file (e.g. at initial setup)
-update(sync) configuration in database with configuration from JSON file (e.g. once new configuration entry was added/changed in JSON file) 

Usage: 
  cli.js [options] -t <task>   

Options:
  -c <config_file> - file name which contains all profiles that are supposed to be loaded to the database(default: profiles.json)
  -r <repository_subfolder> - subfolder name which contains <config_file>  (default: repository)
  -a <active_subfolder> - subfolder name where generated files with profiles from the database should be stored (default: active)  
  -b <base_folder> - path to a base folder with profiles library and which should contain <repository_subfolder> and <active_subfolder> subfolders (default: process.cwd())   
  -p <profile_name> - profile name to be loaded to or from the database (e.g. 'staging' or 'production')  
  -db <dburl> - mongo connection string pointing to a database that should be used   
  -collection <collection_name> - name of mongo collection that should be used to store/load profiles from (default: profiles)   
  
Tasks:
   [initialize] - initialize configuration in the database based on data from <config_file> (all profiles from <config_file> will be loaded into the database, if something existed in the database it will be removed) 
   [loadprofile] - restore entire profile (specified with <profile_name>) in the database based on data from <config_file>  (it will remove all entries for <profile_name> from database and load <profile_name> entries from <config_file>)
   [deleteprofile] - delete profile (specified with <profile_name>) from the database
   [dumpprofile] - download profile from the database (specified with <profile_name>) from the database