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

nodefig

v0.0.1

Published

Simple configuration module for node apps. It will look for application config and then environment config.

Downloads

3

Readme

Config.js

A very simple configuration control for Node.js applications. You can set and get... that's basically all you need.

WARNING

This has yet been published to npm as it is still in aplha.

The Getter

There are 3 levels of configuration that the getter will look for. Firstly, it'll look under your project's configuration (stuff you've set with the setter). Secondly it'll look in the process environment list (this is pretty handy when placing the same code on different servers). If all else fails, it will just use whatever default value you want to give it.

Examples

// connect.js
var config = require('config.js'),
    db     = require('db');

db.connect(config.get('DB_USER', 'root'), config.get('DB_PASS', 'passpass'));

'Simples!' In the above example the values would be:

DB_USER: 'root'
DB_PASS: 'passpass'

That's because no config has been set. However, I could override this at an environment level:

$ DB_USER=my_user DB_PASS=my_pass node connect.js

Or, if you use a cloud service, like node jitsu, you can set the environment variables then restart your app.

$ jitus env set DB_USER my_user
$ jitsu env set DB_PASS my_pass
$ jitsu restart

Sweet! But what if I want to override the configuration at a project level? Simple, just use the setter.

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

config.set('DB_USER', 'project_user');
config.set('DB_PASS', 'project_pass');
// connect.js
var config = require('config.js'),
    db     = require('db');

db.connect(config.get('DB_USER', 'root'), config.get('DB_PASS', 'passpass'));

Easy.

Using config.js with Express.js

So, express already has a configuration object; the express instance itself:

var express = require('express'),
    app     = express();

app.set('mung', 'face');
app.get('mung'); // 'face'
app.get('foo', 'bar'); // /bar

That's all good, but it doesn't take the environment variables in to consideration. So you can now use all the functionality config.js has within the express instance.

var express = require('express'),
    config  = require('config.js'),
    app     = express();

config.use(app);

config.set('view engine', 'jade');
config.get('view engine');         // 'jade'
app.get('view engine');            // jade'
app.get('DB_USER');                // 'my_user'

As you can see, you can continue the the app variable and it will update the config's properties too.

You can also use the use method more than once to add the several of your ready made config objects.

var express           = require('express'),
    somethingExpressy = require('otherExpress'),
    config            = require('config.js');

config.use(express());
config.use(somethingExpressy());

config.get('static directory'); // Will search through all objects before using the default behaviour.