UNPKG

jarvisnode

Version:

A library written in Node.js used to communicate with my Jarvis project

44 lines (30 loc) 738 B
var fs = require('fs'); var map = null; var path = null; var p = require('path'); /** * Handle the library settings * @module jarvisnode/modules/config */ module.exports = { init: function(confPath, cb) { path = confPath; fs.exists(confPath, function (exists) { var readPath = p.join(__dirname, '/config.json'); if (exists) readPath = path; fs.readFile(readPath, 'utf8', function(err, buf) { fs.writeFile(path, buf, function() { map = JSON.parse(buf); cb(err); }); }); }); }, save: function(cb) { fs.writeFile(path, JSON.stringify(map), cb); }, get: function() { return map; } };