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

jconf

v0.0.4

Published

Simple node.js configuration engine

Downloads

11

Readme

JConf - Simple node.js config engine

Overview

It is really simple configuration module. Das't require any options for run.
Just put some config files to your project root and you are ready!

Examples

This examples shows how to use jconf in 10 seconds.

For example, you have a default config like:

{
  "server": {
    "host": "localhost",
    "port": 3000
  },
  "database": {
    "host": "rds.server.com",
    "port": 3306,
    "user": "someUser",
    "password": "somePassword"
  }
}

This is config you use in one or more servers, but you want keep it in your repository for simple deploy.
But, what about your local machine or other developers?

Create file "config.js" or "config.json" in your project dir and just use:

const config = require('jconf');

console.log(config); 
/*
{
  "server": {
    "host": "localhost",
    "port": 3000
  },
  "database": {
    "host": "rds.server.com",
    "port": 3306,
    "user": "someUser",
    "password": "somePassword"
  }
}
*/

Now, just create new file, called "config.local.js" or "config.local.json" with content:

{
  "server": {
    "port": 8000
  },
  "database": {
    "host": "localhost",
    "user": "root",
    "password": ""
  }
}

Run previous example and you get merged config like:

{
  "server": {
      "host": "localhost",
      "port": 8000
    },
    "database": {
      "host": "localhost",
      "port": 3306,
      "user": "root",
      "password": ""
    }
}

Now add "config.local.json" to your .gitignore file and that allows you always keep actual config in repo and use different options in local machine.

Pretty simple? :)

What a minute! What about different environments?

Just create additional config files like:

  • config.production.json
  • config.development.json
  • config.etc.json

And run your script with NODE_ENV param:

NODE_ENV=produnction node app.js
# jconf load config.js and after that
# merge with config.production.json
NODE_ENV=development node app.js
# jconf load config.js and after that
# merge with config.development.json

Still is simple? ;)

Advanced

jconf load and merge configs in next order:

  • config.js or config.json
  • config.local.js or config.local.json
  • config.NODE_ENV.js or config.NODE_ENV.json

Each next file, overrides previous config via merge way

Options

You can pass additional options to jconf via global object:

  • baseName - Change default config file name prefix for files. Default: config
  • configPath - Change default config search path. Default: script start dir
  • excludeConfigName - After loading, jconf place to config object property _configName with loaded config name. if you don't need it, just set true. Default: false
  • debug - If true, jconf will be print debug output to via console.log. Default: false

Example

'use strict';

global.jconf = {
  configPath: __dirname + '/config',
  excludeConfigName: true
}
const config = require('jconf');

Why global ???!!!
jconf try to load your configs on first require and cache result config to nodejs modules cache. It helps reduce file operations on application load or in dynamic require.

At this moment I don't have any idea, how change it and keep caching, pull requests are welcome!