class AutoSaveJSON {
constructor(path) {
this.data = require(path);
}
save() {
fs.writeFile(path, JSON.stringify(this.data), err => console.dir(err, {colors: true})
}
set(key, value) {
this.data[key] = value;
this.save()
}
get(key) {
return this.data[key]
}
}
const json = new AutoSaveJSON('./some_data.json')
json.set('key', 'value')
json.get('key') === 'value'