-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
46 lines (36 loc) · 799 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require ('fs');
function writeDb(updatedDb) {
fs.writeFileSync("/tmp/db.json", JSON.stringify(updatedDb, null, 2));
}
function readDb() {
return JSON.parse(fs.readFileSync("/tmp/db.json"));
}
module.exports = {
storedToken: {
get: () => {
return readDb().token;
},
add: (newToken) => {
const newDb = {
token: newToken
}
writeDb(newDb)
}
}
}
const storedToken = {
name: 'foo',
releaseKraken: () => {
console.log('krakenreleased')
}
}
// const ourData = {
// name: 'Foo mc foo',
// age: 55,
// school: 'playway'
// }
// fs.writeFileSync("./foo.json", JSON.stringify(ourData, null, 2));
// const foo = JSON.parse(fs.readFileSync("./foo.json"));
// console.log(foo.school)
// const theToken = db.token.get()
// console.log(theToken)