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

json-cfg

v0.1.6

Published

The json configuration holder for developers who need to load configurations from json files and share the loaded configurations within the whole project

Downloads

16

Readme

node-json-cfg

This module is designed to provide a more convenient shared configuration system.

Overview

When coding in nodejs environment, you may encounter conditions in which you need to keep track all configurations among submodules. To fulfill the requirement, you may come up with a customized module. But typically, even the main module and the submodules are dependent to the same customized module, you'll end up with modules with different instances. This is very frustrating...

No worry, this module is also designed to solve the above situation. As long as you include the module with the same version, you'll have the ability to share configuration storage among all your modules and submodules.

Feature

  • An easy to use configuration holder
  • Easy to load / access
  • Synchronize among all modules including ones required by submodules

Installation

All in have to do is...

$ npm install json-cfg

Require the module within your scripts and use it!

let config = require( 'json-cfg' );

Examples

General Usages

All configurations can be accessed via conf property of the module.
For example, you have two configuration files config1.json and config2.json

// config1.json

{
	"https": false,
	"address": "localhost",
	"port": 8080
}
// config2.json

{
	"https": true,
	"address": "www.google.com",
	"port": 443
}

You can load them and write in local moduleA...

// moduleA.js

// You can load multiple configurations and this module will merge them into the same space
let config = require( 'json-cfg' ).load( './config1.json' ).load( './config2.json' );

// writing configuration
config.conf.port = "80";

and you can access the configurations in local moduleB...

// moduleB.js

let config = require( 'json-cfg' );
let {https:isHttps, address, port} = config.conf;

const http = require( isHttps ? 'https' : 'http' ).createServer();

// ... do http initialization logics here...
http.listen(port, address);

Interestingly, you can also access the same configurations from dependent external module external.js

let config = require( 'json-cfg' );

module.exports = {
	showConf: ()=>{
		console.log(config.conf.address); // www.google.com
		console.log(config.conf.port); // 80
		console.log(config.conf.https ? 'https' : 'http'); // https
	}
};

Accessing the Shared Space

You can get the shared configuration space using following line

let shared = config.trunk;

Separated Spaces

In some conditions, you may want to store different configurations separately.
This can be done via following usage...

let otherSpace = config.obtain( 'identifier' );

You can always obtain the same configuration space by the same space identifier.
Moreover, if you're done with specific space, you can remove it via following line...

config.remove( 'identifier' );

Reseting

If you want to clear a space, just do the following lines...

config.reset();
config.obtain( 'identifier' ).reset();

Note that the reset method only replace the internal configuration holder with newer object. This method won't affect the target object itself.