Added
- Presets for common use cases (JSON, localStorage and sessionStorage)
Instead of writing this:
import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'
const adapter = new JSONFile(file)
const defaultData = { posts: [] }
const db = new Low(adapter, defaultData)
await db.read()
You can now do:
import { JSONPreset } from 'lowdb/node'
const defaultData = { posts: [] }
const db = await JSONPreset('db.json', defaultData)
This will also use the Memory
adapter automatically when NODE_ENV=test
making tests faster.
- TypeScript: lowdb supports the broader
fs.PathLike
type which lets you useURL
in addition tostring
.
// This is now possible and will read from 'db.json' relatively to the current module path
JSONPreset(new URL('db.json', import.meta.url), defaultData)