First commit
This commit is contained in:
commit
696a772451
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
test.json
|
17
index.js
Normal file
17
index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
let fs = require("fs");
|
||||||
|
function loadDB(databaseFile) {
|
||||||
|
let _db, db;
|
||||||
|
if (fs.existsSync(databaseFile)) {
|
||||||
|
_db = JSON.parse(fs.readFileSync(databaseFile, "utf8"));
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(databaseFile, JSON.stringify({}));
|
||||||
|
_db = {};
|
||||||
|
}
|
||||||
|
return new Proxy(_db, {
|
||||||
|
set: function (target, key, value) {
|
||||||
|
target[key] = value;
|
||||||
|
fs.writeFileSync(databaseFile, JSON.stringify(target));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.loadDB = loadDB;
|
12
package.json
Normal file
12
package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "jsondb",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user