SkyNX/SkyNX-Streamer/Devlord_modules/DB.js

21 lines
532 B
JavaScript
Raw Normal View History

2020-04-16 00:15:44 +00:00
//Authour: Dustin Harris
//GitHub: https://github.com/DevL0rd
var fs = require('fs');
var getDirName = require('path').dirname;
function load(path) {
var contents = fs.readFileSync(path).toString('utf-8');
return JSON.parse(contents)
}
function save(path, obj) {
var contents = JSON.stringify(obj, null, "\t")
fs.mkdir(getDirName(path), { recursive: true }, function (err) {
if (err) throw err;
fs.writeFileSync(path, contents, function (err) {
if (err) throw err;
});
});
}
exports.load = load;
exports.save = save;