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

msoc-config

v0.2.0

Published

This module provides a configuration facility for straightforward, per-environment configuration, with runtime typechecking in both Typescript and Javascript environments.

Downloads

10

Readme

mosc-config configuration

This module provides a configuration facility for straightforward, per-environment configuration, with runtime typechecking in both Typescript and Javascript environments.

The intent is to provide a small but useful feature set to serve common requirements and standarding configuration paradigms across multiple projects, without any environment-checking in your code.

Features

  • Separate configuration files for each environment
  • Configuration is a plain JS object
  • Safe type-checking for strings, booleans, floats and arrays
  • Supports nested objects
  • Inline defaulting
  • .env preloading
  • 4 environments: development, test, staging, production
  • Fallback configuration for test and staging environments

Quickstart

The default location for config files is process.cwd() + /config (this is configurable too)

config/development.ts

export default  {
    api_server: 'https://toolbox.dev',
    api_server_timeout: 5
    api_client_secret: process.env.CLIENT_SECRET,
    squizzle_enabled: true,
    db { 
        server: 'db.toolbox.dev:5432'
    }
};

Your code

import { Configuration } from 'config'

const config = Configuration.getConfig();

const api_server = config.getString('api_server'); // https://toolbox.dev
const do_squizzle = config.getBoolean(squizzle_enabled, false); // true; if absent from config, it'll be false
const db_server = config.get('db.server'); // db.toolbox.dev:5432
const db_username = config.get(db.username'); // null, since not in file and no default.

The module codifies and implements a few rules intended to make configuration straightforward and predictable. You supply a config file for every environment you intend to support. Code consumers grab config from the module, and should not need, in general cases, to check the environment directly, just use the supplied config values.

Configuration files are separate per-environment, to make separation a little cleaner and reduce the need for code/conditionals in the config file. Ideally, these files are as close as possible to being just simple key-value declarations.

How It Works

There are 4 supported environment types, mapping to the 3 conventional node environments - development, test, and production, plus an extra staging.

  • First, Configuration loads a .env file, if there's one in cwd, before loading the environment's config.
  • Then, Configuration loads ${environment}.ts from the designated config folder
    • This config file is expected to export a default object containing config keys
    • The test environment will fall back to development if there's no test.ts file
    • Similarly, the staging environment will fall back to production settings.
  • Set config and env directories (before grabbing an instance) with Configuration.configFileDir and Configuration.envFileDir
  • Get the configuration object using Configuration.getConfig()
  • Access config values via one of the get methods.
    • getArray()
    • getFloat()
    • getInteger()
    • getObject()
    • getString()

The tests are probably to best way to see usage in-action. Also see the docs in the docs folder.

Future/TODO

  • Configuration is a good access point for feature, rollout, and experiment inclusion checking, this is a possibilty down the road, either via subclassing or via interfaces to these related systems.