confiture
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

NPM version Build Status Dependency Status

Configuration library with validation using json-schema, compression, and encryption

The main goal of confiture is to provide configuration with:

  • systematic validation using JSON schema.
  • the option to compress the configuration file.
  • the option to encrypt the configuration file.

Optionally, the configuration could be manipulated from a CLI using commander and json commander.

Version V2.x has been migrated from Javascript to Typescript.

Install

$ npm install --save confiture

Usage

Synchronously load some JSON

var confiture = require('confiture');
 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
});
 
var conf = configurator.load();
//Will load __dirname/appname/conf.json
//conf will contain the configuration data
//or an Error object if the validation has failed.
 

Asynchronously save some JSON through a stream

var confiture = require('confiture');
 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
});
 
var conf = {
    "email": "support@mycompany.com",
    "project": "bestProject"
};
 
var stream = configurator.save(conf);
//Will save the configuration in __dirname/appname/conf.json
//and return a stream
//or an Error object if the validation has failed.

Synchronously save some JSON

var confiture = require('confiture');
 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
});
 
var conf = {
    "email": "support@mycompany.com",
    "project": "bestProject"
};
 
var saveResult = configurator.saveSync(conf);
//Will save the configuration in __dirname/appname/conf.json
//and return OK
//or an Error object if the validation has failed.

Compression

You can ask for the json file to be compressed. Only gz is supported at the moment.

 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
    compression: "gz"
});
 
//The generated file name will be __dirname/appname/conf.json.gz
 

Encryption

You can ask for the json file to be encrypted. When encryption is on, compression is not supported though.

Most ciphers should be supported. You can check the list by typing:

require('crypto').getCiphers();

Encrypted configuration:

 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
    encryption: "aes-256-cbc",
    password: "my secure password"
});
 
//The generated file name will be __dirname/appname/conf.json.aes-256-cbc
 

Backup

You can ask for the json file to be backed up before saving a new configuration.

 
var configurator = confiture({
    name: "conf",
    schema: __dirname + "/schemas/conf.schema.json",
    baseDirectory: __dirname,
    relativeDirectory: "appname"
    backupBeforeSave: true
 
});
 
//The backup file name will be something like __dirname/appname/conf.json.bak-2015-05-02T17:44:25+01:00
 

Understanding the configuration

You can have an insight about the configuration by logging this:

 
console.log(configurator.configuration());
 

License

MIT © Olivier Huin

Package Sidebar

Install

npm i confiture

Weekly Downloads

4

Version

2.1.1

License

MIT

Unpacked Size

786 kB

Total Files

50

Last publish

Collaborators

  • olih