Gathering detailed insights and metrics for @wqhscope/lowdb
Gathering detailed insights and metrics for @wqhscope/lowdb
Gathering detailed insights and metrics for @wqhscope/lowdb
Gathering detailed insights and metrics for @wqhscope/lowdb
npm install @wqhscope/lowdb
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.9
Supply Chain
98.7
Quality
75
Maintenance
100
Vulnerability
100
License
JavaScript (99.12%)
Shell (0.88%)
Total Downloads
271
Last Day
1
Last Week
1
Last Month
9
Last Year
75
MIT License
22,145 Stars
545 Commits
953 Forks
243 Watchers
2 Branches
35 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
3.0.0
Package Id
@wqhscope/lowdb@3.0.0
Unpacked Size
29.57 kB
Size
6.78 kB
File Count
25
NPM Version
8.3.0
Node Version
16.13.1
Cumulative downloads
Total Downloads
Tiny local JSON database for small projects 🦉
1// This is pure JS, not specific to lowdb ;) 2db.data.posts.push({ id: 1, title: 'lowdb is awesome' }) 3 4// Save to file 5db.write()
1// db.json 2{ 3 "posts": [ 4 { "id": 1, "title": "lowdb is awesome" } 5 ] 6}
If you like lowdb, see also xv (test runner) and steno (fast file writer).
Become a sponsor and have your company logo here.
Please help me build OSS 👉 GitHub Sponsors
1npm install lowdb
Lowdb 2 is a pure ESM package. If you're having trouble importing it in your project, please read this.
1import { join, dirname } from 'path' 2import { Low, JSONFile } from 'lowdb' 3import { fileURLToPath } from 'url' 4 5const __dirname = dirname(fileURLToPath(import.meta.url)); 6 7// Use JSON file for storage 8const file = join(__dirname, 'db.json') 9const adapter = new JSONFile(file) 10const db = new Low(adapter) 11 12// Read data from JSON file, this will set db.data content 13await db.read() 14 15// If file.json doesn't exist, db.data will be null 16// Set default data 17db.data ||= { posts: [] } 18// db.data = db.data || { posts: [] } // for node < v15.x 19 20// Create and query items using plain JS 21db.data.posts.push('hello world') 22db.data.posts[0] 23 24// You can also use this syntax if you prefer 25const { posts } = db.data 26posts.push('hello world') 27 28// Write db.data content to db.json 29await db.write()
1// db.json 2{ 3 "posts": [ "hello world" ] 4}
Lowdb now comes with TypeScript support. You can even type db.data
content.
1type Data = { 2 posts: string[] // Expect posts to be an array of strings 3} 4const adapter = new JSONFile<Data>('db.json') 5const db = new Low<Data>(adapter) 6 7db.data 8 .posts 9 .push(1) // TypeScript error 🎉
You can easily add lodash or other utility libraries to improve lowdb.
1import lodash from 'lodash' 2 3// ... 4// Note: db.data needs to be initialized before lodash.chain is called. 5db.chain = lodash.chain(db.data) 6 7// Instead of db.data, you can now use db.chain if you want to use the powerful API that lodash provides 8const post = db.chain 9 .get('posts') 10 .find({ id: 1 }) 11 .value() // Important: value() needs to be called to execute chain
For CLI, server and browser usage, see examples/
directory.
Lowdb has two classes (for asynchronous and synchronous adapters).
new Low(adapter)
1import { Low, JSONFile } from 'lowdb' 2 3const db = new Low(new JSONFile('file.json')) 4await db.read() 5await db.write()
new LowSync(adapterSync)
1import { LowSync, JSONFileSync } from 'lowdb' 2 3const db = new LowSync(new JSONFileSync('file.json')) 4db.read() 5db.write()
db.read()
Calls adapter.read()
and sets db.data
.
Note: JSONFile
and JSONFileSync
adapters will set db.data
to null
if file doesn't exist.
1db.data // === null 2db.read() 3db.data // !== null
db.write()
Calls adapter.write(db.data)
.
1db.data = { posts: [] } 2db.write() // file.json will be { posts: [] } 3db.data = {} 4db.write() // file.json will be {}
db.data
Holds your db content. If you're using the adapters coming with lowdb, it can be any type supported by JSON.stringify
.
For example:
1db.data = 'string' 2db.data = [1, 2, 3] 3db.data = { key: 'value' }
JSONFile
JSONFileSync
Adapters for reading and writing JSON files.
1new Low(new JSONFile(filename)) 2new LowSync(new JSONFileSync(filename))
Memory
MemorySync
In-memory adapters. Useful for speeding up unit tests.
1new Low(new Memory()) 2new LowSync(new MemorySync())
LocalStorage
Synchronous adapter for window.localStorage
.
1new LowSync(new LocalStorage(name))
TextFile
TextFileSync
Adapters for reading and writing text. Useful for creating custom adapters.
If you've published an adapter for lowdb, feel free to create a PR to add it here.
You may want to create an adapter to write db.data
to YAML, XML, encrypt data, a remote storage, ...
An adapter is a simple class that just needs to expose two methods:
1class AsyncAdapter { 2 read() { /* ... */ } // should return Promise<data> 3 write(data) { /* ... */ } // should return Promise<void> 4} 5 6class SyncAdapter { 7 read() { /* ... */ } // should return data 8 write(data) { /* ... */ } // should return nothing 9}
For example, let's say you have some async storage and want to create an adapter for it:
1import { api } from './AsyncStorage' 2 3class CustomAsyncAdapter { 4 // Optional: your adapter can take arguments 5 constructor(args) { 6 // ... 7 } 8 9 async read() { 10 const data = await api.read() 11 return data 12 } 13 14 async write(data) { 15 await api.write(data) 16 } 17} 18 19const adapter = new CustomAsyncAdapter() 20const db = new Low(adapter)
See src/adapters/
for more examples.
To create an adapter for another format than JSON, you can use TextFile
or TextFileSync
.
For example:
1import { Adapter, Low, TextFile } from 'lowdb' 2import YAML from 'yaml' 3 4class YAMLFile { 5 constructor(filename) { 6 this.adapter = new TextFile(filename) 7 } 8 9 async read() { 10 const data = await this.adapter.read() 11 if (data === null) { 12 return null 13 } else { 14 return YAML.parse(data) 15 } 16 } 17 18 write(obj) { 19 return this.adapter.write(YAML.stringify(obj)) 20 } 21} 22 23const adapter = new YAMLFile('file.yaml') 24const db = new Low(adapter)
Lowdb doesn't support Node's cluster module.
If you have large JavaScript objects (~10-100MB
) you may hit some performance issues. This is because whenever you call db.write
, the whole db.data
is serialized and written to storage.
Depending on your use case, this can be fine or not. It can be mitigated by doing batch operations and calling db.write
only when you need it.
If you plan to scale, it's highly recommended to use databases like PostgreSQL, MongoDB, ...
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
0%
1
Compared to previous day
Last Week
0%
1
Compared to previous week
Last Month
28.6%
9
Compared to previous month
Last Year
31.6%
75
Compared to previous year