diff --git a/jsondb.js b/jsondb.js index 5d147cc..02f8d03 100644 --- a/jsondb.js +++ b/jsondb.js @@ -21,7 +21,10 @@ module.exports = function(name){ this.init = function(){ fs.readFile(this.file, (err, data) => { - if (err) throw err; + if (err.errno==-2 && err.code == "ENOENT"){ + this.set(db); + return; + }else if (err) throw err; this.json = JSON.parse(data); }); }