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 🙏

© 2026 – Pkg Stats / Ryan Hefner

perrier

v0.3.3

Published

Powerful config loader (based on json)

Readme

Perrier

Perrier is a powerful JSON loader, which can use to load multi external JSON files, and merge to one JS object for large Node.js application uses.


Quick Example

config/foo.json

{
    foo: 1
}

config/bar.json

{
    bar: 2
}

app.js

var config = require('perrier').create();
config.merge({
    './config/foo.json',
    './config/bar.json', 
    {
        baz: 3
    }
});

console.log(config); 

OUTPUT

{ 
    foo: 1, 
    bar: 2, 
    baz: 3 
}

Why We Need This Tool

Manage Config Easily

  • decompose large config file into multi config files
  • combine different config files in different situations
  • merge multi config file in one shot

Powerful JSON Format

  • you can leave comment on JSON file
  • you can add template string on JSON file, and replace automatically
  • you can link other config file on JSON field, and load automatically

New Feature (added on v0.3.0)

  • supported yaml format

Usage

1. Powerful JSON

config/sample.json

{
    event: "archive",
    rule: /warn/,
    interval: 1000 * 60 * 10 // do it every 10 min
}

app.js

var config = require('perrier').create();
config.merge( './config/sample.json' );

console.log( config ) );

OUTPUT

{ 
    event: 'archive', 
    rule: /warn/, 
    interval: 60000
}

Supported comment / expression on JSON file.


2. Template Replace

config/production.json

{
    // global is reserved CONFIG field, which will use to render template field on future merge
    global: {
        NODE_ENV: 'production',
        LOG_LEVEL: 'info'
    }
}

config/logger.json

{
    logger: {
        logPath: '/home/logs/{{NODE_ENV}}.log
        logLevel: '{{LOG_LEVEL}}+error'
    }
}

app.js

var config = require('perrier').create();
config.merge(
    './config/production.json',
    './config/logger.json'
);
console.log( config ) );

OUTPUT

{ 
    logger: {  
        logPath: '/home/logs/production.log', 
        logLevel: 'info+error' 
    }
}

The global field will be template source, if any other field contains {{key}}, it will be replaced with corresponding content.

So that you can change the first arg in different environment, but keep same log config file.


3. Link to Other Config

config/main.json

{
    fooApp: 'conf: ./foo.json ', //link to external file
    barApp: {
        bar: true
    }
}

config/foo.json

{
    foo: true // which will be combined into main.json
}

app.js

var config = require('perrier').create();
config.merge( './config/main.json' );

console.log( config ) );

OUTPUT

{ 
    fooApp: { 
        foo: true 
    }, 
    barApp: { 
        bar: true 
    } 
}

If any fields start with conf:, then the engine will try to load an external file and replace here.

So that you can decompose large files into multi config files, and do the flexible combinations.

This feature also supports template render, you can add {{key}} in anywhere.


4. Runtime Config

config/main.json

{
    type: 'http',
    maxSocks: 5
}

app.js

var config = require('perrier').create();
config.merge(
    './config/main.json', 
    {
        maxSocks: 10
    }
);
console.log( config ) );

OUTPUT

{ 
    type: 'http', 
    maxSocks: 10 
}

You can load a static file, and overwrite with runtime config if you need.

Loader supports file path / plain object, all of those will be merged in sequentially.


5. Monitor Method

app.js

function monitor(err, index, fileName) {
    console.log(arguments);
}

var config = require('perrier').create({
    monitor: monitor
});

config.merge({
    './config/a.json', 
    './config/b.json',
    monitor // latest arg can be monitor function
});

Engine will load config silently, but you can add a monitor function, it will be called once every config merged.

6. Supported YAML

All feature supported on yaml format, see example

( must install "js-yaml" manually )


APIs

perrier.create( options )

  • options.rootPath {String} - all config file will be resolved with root path. (default: process.cwd() )
  • options.globalFields {Object} - default template source (optional)
  • options.monitor {Function} - this fn will be called once every config merged

Example

// config/base.json
{
    server: '{{NODE_ENV}}
}

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

var config = perrier.create({
    rootPath: path.join(__dirname, 'config'),
    globalFields: {
        NODE_ENV: process.env.NODE_ENV || 'development'
    }
});

config.merge('base.json'); // base.json will be converted to "__dirame/config/base.json""
console.log(config); // { server: 'development' }

init method, you can also call var Perrier = require('perrier'); new Perrier();

merge( source1, [, source2, ..., sourceN ])

See above usage, or example

getField( filedName )

return config.filedName or undefined

Example

config.getField('logger');

getGlobal()

return global fields ( the template source )

Example

config.getGlobal();

Questions?

If you have any questions, feel free to create a new issue.