Search code examples
javascriptelectronnedb

NEDB persistance in Electron app


I am trying to connect to nedb from electron app. CRUD operations work great. BUT I don't see db file (D:/my.db, checked for hidden files). File exists somewhere, because it keeps data even after machine reboot. I suspect that electron threats my path as relative, but I can find it anywhere.

var Datastore = require('nedb'), db = new Datastore({filename : 'D:/my.db', autoload: true});
var doc = { hello: 'world'
           , n: 5
           , today: new Date()
           , nedbIsAwesome: true
           , notthere: null
           , notToBeSaved: undefined  // Will not be saved
           , fruits: [ 'apple', 'orange', 'pear' ]
           , infos: { name: 'nedb' }
           };

db.insert(doc, function (err, newDoc) {   // Callback is optional
   // newDoc is the newly inserted document, including its _id
   // newDoc has no key called notToBeSaved since its value was undefined
});

Solution

  • The doc says

    If you specify a filename, the database will be persistent, and automatically select the best storage method available (IndexedDB, WebSQL or localStorage) depending on the browser.