XTweet/storage.js

21 lines
388 B
JavaScript
Raw Normal View History

2019-07-25 17:43:55 +02:00
const fs = require('fs')
const STORAGE_FILE = 'storage.json'
let storage = {
init: function() {
if (!fs.existsSync(STORAGE_FILE)) {
fs.writeFileSync(STORAGE_FILE, '{}')
}
let raw = fs.readFileSync(STORAGE_FILE)
this.data = JSON.parse(raw)
},
save: function() {
fs.writeFileSync(STORAGE_FILE, JSON.stringify(this.data))
}
}
module.exports = storage;