Make your json config support comments.
$ npm install json-comments
// require `json-comments` in your main module only once
require('json-comments');
config.json
{
// this is host
"host" : "localhost",
"port" : 3000, //port
"url" : "https://github.com/numbcoder", /* url */
/*
* comments support for json
*/
"username": "abc"
}
app.js
require('json-comments');
var config = require('./config');
console.log(config);
// ...
var JSONC = require('json-comments');
var fs = require('fs');
var content = fs.readFileSync('./config.json', 'utf8');
// parse JSON String
var config = JSONC.parse(content);
console.log(config);
var JSONC = require('json-comments');
var fs = require('fs');
var content = fs.readFileSync('./config.json', 'utf8');
// remove comments and spaces from JSON String
var JsonStr = JSONC.minify(content);
MIT