github typicode/lowdb v6.1.0

latest releases: v7.0.1, v7.0.0, v6.1.1...
11 months ago

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 use URL in addition to string.
// 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)

Don't miss a new lowdb release

NewReleases is sending notifications on new releases.