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

@cimpresscloud/metafig

v0.3.1

Published

A configuration file for your configuration file.

Downloads

6

Readme

Build Status Code Climate Test Coverage

dependencies Status devDependencies Status

npm (scoped) npm

METAFIG

Metafig is a library for loading configuration values from external services like AWS Parameter Store, Environment Variables, S3 objects, etc. All of this is configurable from a single place, making it easy to synthesize different values from different locations.

Why?

We had a bunch of lambda functions with a bunch of different configuration methods. Some used S3 before lambda had encryption helpers for environment variables. Some used environment variables. Some used the Parameter Store.

While we migrated most of them to the Parameter store, we wanted to:

  1. Make it easier to mix-and-match
    • We had a few things too big for the Parameter Store
    • There are a few things that make more sense as environment variables.
  2. Make it easier to migrate in the future if we change our mind.

Installing

npm install --save @cimpresscloud/metafig

Example

./config.json

{
  "plugins": {
    "database": {
      "awsParam": {
        "path": "/production/myapp/database",
        "decryption": true
      }
    },
    "api": {
      "awsParam": {
        "path": "/production/myapp/api",
        "decryption": true
      },
      "environment": {
        "baseUrl": "API_BASE_URL"
      }  
    }
  }
}

./index.js

const metafig = require('metafig');
metafig(require('./config.json'), 'plugins')
  .then(config => {
    var db = new Db(config.plugins.database.connectionString);
    return db.query('SELECT * FROM MyTable');
  });

In this case, the config object looks something like:

{
  plugins: {
    database: {
      connectionString: "sql://mydatabase.example.com:5678/db",
      username: "myApplication",
      password: "secret"
    },
    api: {
      token: "123456",
      baseUrl: "https://myapi.example.com"
    }
  }
}

As you can see, it pulled some items from environment variables, and some from the AWS SSM Parameter Store.

Providers

Metafig comes with 3 built-in configuration providers:

awsParam

The awsParam provider can pull down items from the AWS SSM Parameter Store. It can take 2 parameters:

"awsParam": {
  "path": "/app", // the path to the hierarchy in SSM to pull down
  "decryption": true // whether or not to decrypt SecureStrings
}

It will pull down every parameter listed under the specified path and put them into the configuration object, nesting objects if there are deeper configurations.

awsS3

The awsS3 provider can pull down JSON configuration snippets as objects from S3. It can accept any parameter for the getObject API action:

"awsS3": {
  "Bucket": "metafig-integration-test",
  "Key": "test.json"
}

It will pull down the specified object and run it through the JSON parser.

environment

The environment provider pulls values out of environment variables and maps them to configuration items.

"environment": {
  "myValue": "USERNAME"
}

Take the USERNAME environment variable and puts it into the myValue property of your configuration.

literal

The literal provider just uses the literal value passed to it:

"literal": {
  "username": "nmaclennan"
}