Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read from a JSON file if it requires default data? #592

Open
bobbintb opened this issue Jun 15, 2024 · 2 comments
Open

How to read from a JSON file if it requires default data? #592

bobbintb opened this issue Jun 15, 2024 · 2 comments

Comments

@bobbintb
Copy link

bobbintb commented Jun 15, 2024

I'm really struggling trying to understand the examples in the readme and elsewhere when trying to read a file. I have a JSON file and I am trying to load and read from. For example:

import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'

const adapter = new JSONFile('file.json')
const db = new Low(adapter)
await db.read()
console.log(db.data)

Whatever variation I try, it keeps saying I am missing the default data. The example in the readme to read or create a file includes the default data, which doesn't make any sense to me because it is just an empty object and when I try that, I get an empty database instead of the data from my file. I really don't understand how this is supposed to work.

@tetuaoro
Copy link

tetuaoro commented Aug 1, 2024

Default data is a model.

@michielveen
Copy link

michielveen commented Sep 23, 2024

removed comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants