typicode / lowdb

Simple and fast JSON database
MIT License
21.49k stars 923 forks source link

how to open an existing db, when reopen the application. #452

Closed qyhdt closed 3 years ago

qyhdt commented 3 years ago

Hi, there. When I use this lowdb to create a native db for my little tool, i hit a problem that is: when i open my application again and how can I get the exsiting DB, for every time i have to create db like below sample code: const lowdb = require('lowdb') const FileSync = require('lowdb/adapters/FileSync'); const adapter = new FileSync(dbname) db = lowdb(adapter)

do you have any sample for when users open their app again and get the data from db.

typicode commented 3 years ago

Hi @qyhdt,

See https://github.com/typicode/lowdb#usage it should re-open existing db. The important part is db.read() which populates db.data.