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

fwsp-config

v1.1.5

Published

Configuration file handler

Downloads

569

Readme

Config

Build Status npm version npm

A configuration file handler. Config can load configuration files from a local file system or a remote server.

Once the config module is initialized you can access config properties as you would a simple POJOs JavaScript object.

Examples

Load a local file

const config = require('fwsp-config');
config.init('properties.json')
  .then(() => {
    console.log(config.aws);  
    console.log(config.hydra.aws.apiVersions);
  });

Load a remote file

const config = require('fwsp-config');
config.init('http://cjus.me/properties.json');
  .then(() => {
    console.log(config.aws);  
    console.log(config.hydra.aws.apiVersions);
  });

Load from an object

const config = require('fwsp-config'); config.init({ hydra: { serviceName: 'offers-service', serviceIP: '', servicePort: 7000, serviceType: 'offers', serviceDescription: 'Phone validation for use with first ride class offers', redis: { url: 'redis', port: 6379, db: 15 } } }) .then(() => { console.log(config.hydra);
});



**Usage**

The `config` module returns a Promise and resolves if it successful loaded and parsed a configuration file, otherwise it rejects.  This allows you to sequence application concerns which require configuration data until after the configuration is loaded.

## Sharing config files

Sometimes multiple instances of a service might share the same configuration file. To support this use-case, `config` allows you to define a local configuration file with a location field that specifies the remote location where a configuration file can be found.

```javascript
{
  "location": "http://services.com/imageprocesser/properties.json"
}

Retrieving a plain JS object

The config module behaves like a JavaScript object once it has configuration files loaded. However, for times when you really do what a pure JS object you can use the getObject() method:

const config = require('fwsp-config');
config.init('properties.json')
  .then(() => {
    let obj = config.getObject();
    console.log(JSON.stringify(obj));
  });

Overriding config properties

Config allows you to use plain JavaScript setter patterns to update a loaded configuration file. This is useful in a shared configuration file scenario where each service loads a config file and needs to override one or more fields.

const config = require('fwsp-config');
config.init('properties.json')
  .then(() => {
    config.hydra.serviceName = 'NewServiceName';
    console.log(config.hydra.serviceName);
  });

Implementation details

This config module is implemented using ES6 Proxy support and so it requires NodeJS 6.2.1 or greater Chrome 49 or greater.

Tests

This project has a series of mocha tests in the specs folder.

To run them you'll need mocha installed:

$ npm install mocha -g

then just:

$ npm run test