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

superconfig

v0.2.1

Published

Lightweight config loader. Support for environmental loading, default config, nested keys.

Downloads

8

Readme

superconfig

Lightweight config loader.

Travis David NPM

Install

npm install superconfig --save

Introduction

In large applications you have to deal with a lot of configuration variables. There are plenty of configuration modules out there that expect you to only have one configuration file for each environment. However, when your application grows you may want to encapsulate your variables in separate files in order to keep things overseeable. For example one file for your databases, one file for your server setup and so on. You probably also have some variables that doesn't change throughout your environments. If you only have one file for each environment you need to define every variable for each environment - even if they do not differ.

superconfig let's you...

  • define your configuration variables in separate files
  • have separate directories for your environments
  • have a default set of variables that can be overriden by variables of your actual environment

Usage

Your config directory may look like this:

/config
    /production
        database.js
        server.js
    /development
        database.js

Set up superconfig in a separate file

// config.js
var superconfig = require('superconfig');

module.exports = superconfig({

    // Path to the config directory
    path: '/config',
    
    // The actual environment
    env: process.env.NODE_ENV,
    
    // The default environment,
    // these variables will be extended with those of the actual environment
    denv: 'production'
});

Use your configuration variables

var config = require('/config.js');

// Pass the whole database configuration
var database = new Database(config('database'));

// Use a single value
var user = config('database.user');

// If you are working in the development environment
// superconfig will use the server configuration of your
// production environment, since we didn't provide one
// for the development environment
server.listen(config('server.port'));

Nested directories/variables

You can work with nested directories:

/config
    /production
        /database
            mysql.js
            sqllite.js

Access your variables like:

var user = config('database.mysql.user');

API

superconfig(options)

Params

  • options {Object}

    • options.path {String} Path to your config directory
    • options.env {String} The actual environment
    • options.denv {String} Your default environment
  • Returns

    • {Function} Invoking superconfig() returns a getter function, that let's you access your variables
    • The function takes a path to your variable e.g. database.user