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

configulator

v1.0.2

Published

Handles building a config object based on the environment in which the program is running and allows you to override config properties by passing arguments over the command line.

Downloads

6

Readme

Configulator

Handles building a config object based on the environment in which the program is running and allows you to override config properties by passing arguments over the command line.

Overview

Does your app run in multiple environments? If so, you more than likely have different settings per environment. This module was created to ease the creation of configuration properties within multiple environments. The common properties that do not change exist within the default property while the environment specific values live within their respective environment property. Now, you can easily load the appropriate configuration based on your environment with a single line of code.

Usage

Getting the environment specific configiuration is simple. Follow these steps:

  • Set the node environment variable, NODE_ENV to be the environment your program will be working in. While you are developing, this will most likely be the development environment.
  • Define your default and environment specific configurations in your config file. The name of the file is not important as you should use dependency injection to inject the configuration file to your modules. Here is an example configuration:
config.js
/*jshint node: true*/
'use strict';

exports.wiretree = function configModule(configulator) {
  var config = {
    default: {
      status: {
        SUCCESS: 200,
        CREATED: 201,
        BAD_REQUEST: 400,
        NOT_FOUND: 404,
        INTERNAL_SERVER_ERROR: 500
      },
      methods: {
        GET: 'GET',
        PUT: 'PUT',
        POST: 'POST',
        DELETE: 'DELETE',
        PATCH: 'PATCH'
      },
      standardHeaders: {
        'Content-Type': 'application/json'
      },
      port: 8888,
    },
    development: {
      port: 8000
    },
    production: {
      port: 8001
    }
  };

  return configulator(config);
};

Note that in the above example I am using wiretree to inject configulator. You could require it as a dependency if you choose, but I recommend using a dependency injection framework, such as wiretree. It's simple to setup. Just update your tree as follows:

var Wiretree = require('wiretree');
var wireTree = new Wiretree(__dirname);
var configulator = require('configulator');
wireTree.add(configulator, 'configulator');

In the example above, if you set NODE_ENV to be development, it will overwrite the port to be 8000 instead of 8888.

Overwriting values using arguments

You can also overwrite values using arguments. To do this, simply set your specified argument on overrides. For example:

	node myProgram.js --overrides.port=5827

This will override your environment settings and set the port to 5827, regardless of the environment you are running in.