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

@colucom/osseus-config

v0.2.5

Published

Osseus config

Downloads

16

Readme

JavaScript Style Guide

Osseus Config

The osseus configuration module parses:

  • Environment variables
  • Environment specific files
  • AWS Secrets
  • CLI arguments

The result is an object which will be used by other osseus modules.

Note: all keys will be lowercased in the result object

Install

$ npm install @colucom/osseus-config

Usage

First, create index.js:

const OsseusConfig = require('osseus-config')
const config = await OsseusConfig.init()
console.log(config)

Special Properties

hostInfo

You can use the hostInfo property in the osseus.config object.

In case your app is running on:

  • localhost
    • hostname is the machine name
  • aws
    • hostname is the instance id

These props can be accessed by: osseus.config.hostInfo.hostname and osseus.config.hostInfo.pid

Environment variables

Environment variables must have a CFG_ prefix in order to be parsed by osseus-config

Example

Running:

$ export CFG_SOME_VAR=value
$ node index.js

Will result in:

{ some_var: 'value', keys: [ 'some_var' ] }

Environment specific files

Environment files should be placed under /config folder in the root of the application.

In order for environment files to be parsed, need to define ENV variable matching the file name.

Example

Create /config/LOCAL.js

module.exports = {
  DEBUG: true,
  OSSEUS_LOGGER_LOG_LEVEL: 'debug',
  OSSEUS_SERVER_PORT: '8888'
}

Running:

$ export CFG_ENV=LOCAL
$ node index.js

Will result in:

{ env: 'LOCAL',
  debug: true,
  osseus_logger: { log_level: 'debug' },
  osseus_server: { port: 8888 },
  keys: [ 'env', 'debug', 'osseus_logger', 'osseus_server' ] }

Note that keys starting with "osseus_" are broken into objects, more on this later

AWS Secrets

In order to use AWS Secrets need to define the following variables:

  • ENV (or CFG_ENV)
    • no default
  • APPLICATION_NAME (or CFG_APPLICATION_NAME)
    • no default
  • AWS_SECRETS_ENDPOINT (or CFG_AWS_SECRETS_ENDPOINT)
    • default is https://secretsmanager.eu-west-1.amazonaws.com
  • AWS_REGION (or CFG_AWS_REGION)
    • default is eu-west-1

When all relevant variables are defined, the secrets file names should be ENV/APPLICATION_NAME_*

Another secrets file which will be parsed if exists is ENV/GLOBAL_*

Example

Running:

$ export CFG_ENV=QA
$ export CFG_APPLICATION_NAME=MY_APP
$ node index.js

Will look for QA/MY_APP_* and QA/GLOBAL_* in AWS secrets manager and add the keys to the config result object.

CLI arguments

osseus-config is using yargs to parse CLI arguments.

Example

Running:

$ node index.js --PARAM_1 hello --PARAM_2 123 --PARAM_3 ["'something'"]

Will result in:

{ param_1: 'hello',
  param_2: 123,
  param_3: [ 'something' ],
  keys: [ 'param_1', 'param_2', 'param_3' ] }

Parsers Hierarchy

  1. CLI arguments
  2. AWS Secrets
  3. Environment specific files
  4. Environment variables
Example

Create /config/LOCAL.js

module.exports = {
  MY_PARAM: from_file
}

Running:

$ export CFG_ENV=LOCAL
$ export CFG_MY_PARAM=from_env
$ node index.js --MY_PARAM from_cli

Will result in:

{ my_param: 'from_cli',
  env: 'LOCAL',
  keys: [ 'my_param', 'env' ] }

Contributing

Please see contributing guidelines.

License

Code released under the MIT License.