Enable nconf to parse commented JSON files.
npm install nconf-strip-json-commentsA tiny module enabling nconf to parse commented JSON files.
``javascript
{
// User data
"user": "contact@hoffonline.com", // an email address
"password": "Freedom",
// General setup
"environment": "production", // or "stage", "development"
...
}
`
Comments in JSON files can be helpful e.g. in configuration files. However, comments are not part of the JSON format and standard JSON tools such as JSON.parse can't handle commented files. Instead, tools like jsonminify or strip-json-comments are required. This module enables the nconf module to parse commented JSON files using strip-json-comments.
to parse commented JSON files by default:`javascript
var nconf = require('nconf');
require('nconf-strip-json-comments')(nconf); nconf.file('path_to_some_commented_JSON_');
`
Note that this will enable extended parsing _globally_, that is, for all occurrences of nconf (also in nested modules).
You can also use the module's extended JSON format explicitly:
`javascript
var nconf = require('nconf');
var commentedJsonFormat = require('nconf-strip-json-comments').format; nconf.file({file: 'path_to_some_commented_JSON_', format: commentedJsonFormat});
`To disable a previously globally enabled parsing, use
restore():`javascript
...
require('nconf-strip-json-comments').restore(nconf);
``