GochoMugo / json-concat

A Node.js module for concatenating JSON files and objects. Blends in Connect, Express and your terminal
MIT License
3 stars 2 forks source link

json-concat

A Node.js module for concatenating JSON files and objects. Use it in Node.js as a plain, old module, in Connect and Express as a middleware and in your terminal as an executable.

Installation

$ npm install json-concat --save

To install json-concat onto your command line, you may require passing the -g flag. You may also require some sudo powers to make it work.

$ sudo npm install -g json-concat

Usage

As a plain module in your apps


var jsonConcat = require("json-concat");

jsonConcat({
    src: ["appVars.json", "userVars.json"],
    dest: "./config.json"
}, function (json) {
    console.log(json);
});

As a middleware in Connect/Express apps


var express    = require("express"),
    app        = express(),
    jsonConcat = require("json-concat");

app.use(jsonConcat({
    src: ["appVars.json", "userVars.json"],
    dest: __dirname + "/config.json",
    middleware: true
}));

As an executable in the command line

# As simple as this. Output file should be last
$ json-concat file1.json file2.json ouput.json

# for usage tip, invoke with no args
$ json-concat

Notes

Use Cases

In most cases, while building an Express app, you will end up using jade as your view engine. Jade allows you to pass a javascript object, which may be JSON, for external variables. Instead of writing all your variables in one file, you may distribute the variables across directories and concatenate them later into one file. Eventually passing it to the jade engine.

Tests and Performance

Build Status Coverage Status

To see the tests run on each commit, go to the project's Travis page. If interested in the algorithms used, please read the notes at the beginning of src/json-concat.coffee.

TODO


// Just an example
var json = jsonConcat("appVars.json", "userVars.json", {"name": "@mugo_gocho"});
console.log(json);

License

The MIT License (MIT)

Copyright © 2014-2016 GochoMugo mugo@forfuture.co.ke