v6.1.0
New presets
Before
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()
Now
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 now supports the broader fs.PathLike
type which lets you use URL
type in addition to string
. This is useful for ESM.
// Read from 'db.json' relatively to the current module path using URL
JSONPreset(new URL('db.json', import.meta.url), defaultData)