Skip to content

v6.1.0

Compare
Choose a tag to compare
@typicode typicode released this 14 Oct 01:00
· 14 commits to main since this release

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)