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.
$ 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
var jsonConcat = require("json-concat");
jsonConcat({
src: ["appVars.json", "userVars.json"],
dest: "./config.json"
}, function (json) {
console.log(json);
});
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 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
.
(current working directory)null
to have no file written to./concat.json
false
""
.json
are considered. Symbolic links are ignoredIn 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.
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.
// Just an example
var json = jsonConcat("appVars.json", "userVars.json", {"name": "@mugo_gocho"});
console.log(json);
The MIT License (MIT)
Copyright © 2014-2016 GochoMugo mugo@forfuture.co.ke