2
var Datastore = require('nedb')
  , db = new Datastore({ filename: 'testdb.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) {   
    console.log(newDoc);
});

I can't find "testdb.db" anywhere in my computer, but the console log show the data exist! Any suggestion?

tonywei
  • 677
  • 2
  • 12
  • 25

2 Answers2

1

Finally i know, im using webpack dev server, the file actually there, but only in memory, not written to my harddisk.

tonywei
  • 677
  • 2
  • 12
  • 25
1

Give absolute file location of where the db needs to be stored like below

var db = new DataStore({filename:path.join(__dirname, '/nedb.db'), autoload:true});

Otherwise data will get stored in the location from where you are executing it

Ram
  • 56
  • 5