Skip to content

Instantly share code, notes, and snippets.

@techfort
Last active February 5, 2024 10:27
Show Gist options
  • Save techfort/66898d95ac8ff133720d to your computer and use it in GitHub Desktop.
Save techfort/66898d95ac8ff133720d to your computer and use it in GitHub Desktop.
LokiJS - save to disk and reload
var loki = require('lokijs'),
db = new loki('test.json'),
db2 = new loki('test.json');
var users = db.addCollection('users');
users.insert({
name: 'joe'
});
users.insert({
name: 'john'
});
users.insert({
name: 'jack'
});
console.log(users.data);
db.saveDatabase();
db2.loadDatabase({}, function () {
var users2 = db2.getCollection('users')
console.log(users2.data);
});
@EvgenJin
Copy link

db.saveDatabase();
then
console.log(users.data);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment