const fs = require('fs'); let db = { pre: 0, ins: 0, }; module.exports = function(name){ this.file = "./"+name+".json"; this.json = db; this.get = function(){ return this.json; }; this.set = function(njson){ this.json = njson; fs.writeFile(this.file, JSON.stringify(this.json,null,2), (err) => { if (err) throw err; }); } this.init = function(){ fs.readFile(this.file, (err, data) => { if (err) throw err; this.json = JSON.parse(data); }); } this.init(); }