0

I am facing some difficulty in finding the perfect solution of autosaving data while using LokiJS in NodeJS...

I tried something from the official doc, but all it says is that saveDB is not a function.

Pls help.

1 Answers1

0

When you initialize a new database you can specify the autosave and autoload parameters:

let db = new loki('db.json', {autosave: true, autoload: true});

You can also manually save after you make any changes with:

db.saveDatabase();
Ding
  • 3,065
  • 1
  • 16
  • 27
  • What's the use of Persistence Adapters then? – Devansh Jain Oct 25 '16 at 17:36
  • Will the above written code autosave the data at regular intervals? – Devansh Jain Oct 25 '16 at 17:36
  • Yes, but you can also specify the interval with the `autosaveInterval` parameter (in milliseconds). – Ding Oct 25 '16 at 17:38
  • The purpose of persistence adaptors is to provide alternate (and custom) methods of storage: filesystem, localstorage (browser). If you do not specify a system it will detect a default adaptor based on your environment (filesystem for node and localstorage for browser & cordova). – Ding Oct 25 '16 at 17:47