npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

concisedb

v1.0.3

Published

A database library stores JSON file for Node.js.

Readme

concisedb

npm version codecov GitHub Stars NPM Downloads License Package size

English | 简体中文

A database library stores JSON file for Node.js.

Here is what updated every version if you want to know.

Homepage | Document for v0 | Document for v1

Usage

Basic usage

  1. Install this library

You can also use other package managers like yarn and pnpm instead

npm install concisedb
  1. Example code

This library also supports TypeScript

const ConciseDbSync = require('concisedb').ConciseDbSync
const JSONAdapterSync = require('concisedb').JSONAdapterSync
const path = require('path')

const adapter = new JSONAdapterSync({
  filePath: path.join(__dirname, 'db.json')
})

// Adapter, Default data (optional), Whether realtime update is needed (default: true)
const db = new ConciseDbSync(adapter, { test: [] })

db.data.test.push(1)

console.log(db.data) // Output: { test: [ 1 ] }

// Try modifying the content of db.json
setTimeout(() => {
  db.read()
  console.log(db.data) // Output: Depends on what you modified
}, 10000)
import { ConciseDbSync, JSONAdapterSync } from 'concisedb'
import { join } from 'path'

interface Database {
  test: number[];
  username: string;
}

const init: Database = {
  test: [],
  username: 'John',
}

const adapter = new JSONAdapterSync({
  filePath: join(__dirname, 'db.json')
})

// Adapter, Default data (optional), Whether realtime update is needed (default: true)
const db = new ConciseDbSync(adapter, { test: [] })

db.data.test.push(1)

console.log(db.data) // Output: { test: [ 1 ] }

// Try modifying the content of db.json
setTimeout(() => {
  db.read()
  console.log(db.data) // Output: Depends on what you modified
}, 10000)

The data will automatically update to JSON file by using Proxy

So you can use db.getData() to get a copy of data if you need to change the data many times at once

  1. Don't update automatically
const ConciseDbSync = require('concisedb').ConciseDbSync
const JSONAdapterSync = require('concisedb').JSONAdapterSync
const path = require('path')

const adapter = new JSONAdapterSync({
  filePath: path.join(__dirname, 'db.json')
})
// Give false to the third argument
const db = new ConciseDbSync(adapter, { test: [] }, false)

db.data.test.push(1)

// Use write to update the content to JSON file manully
db.write()
import { ConciseDbSync, JSONAdapterSync } from 'concisedb'
import { join } from 'path'

interface Database {
  test: number[];
  username: string;
}

const init: Database = {
  test: [],
  username: 'John',
}

const adapter = new JSONAdapterSync({
  filePath: join(__dirname, 'db.json')
})
// Give false to the third argument
const db = new ConciseDbSync(adapter, { test: [] }, false)

db.data.test.push(1)

// Use write to update the content to JSON file manully
db.write()
  1. Async APIs

db.getData() remains a synchronous method

const ConciseDb = require('concisedb').ConciseDb
const JSONAdapter = require('concisedb').JSONAdapter
const path = require('path')

(async () => {
  const adapter = new JSONAdapter({
    filePath: path.join(__dirname, 'db.json')
  })
  const db = new ConciseDb()
  // Method db.init should be called after initing the class
  // And should use await to wait this function complete
  // Of course, using .than instand of await is okay
  await db.init(adapter, { test: [] })

  db.data.test.push(1)

  // db.getData() remains a synchronous method
  console.log(db.data, db.getData()) // Output: { test: [ 1 ] } { test: [ 1 ] }

  // Try modifying the content of db.json
  setTimeout(async () => {
    await db.read()
    console.log(db.data) // Output: Depends on what you modified
  }, 10000)
})()
import { ConciseDb, JSONAdapter } from 'concisedb'
import { join } from 'path'

(async () => {
  interface Database {
    test: number[];
    username: string;
  }

  const init: Database = {
    test: [],
    username: 'John',
  }

  const adapter = new JSONAdapter({
    filePath: join(__dirname, 'db.json')
  })
  const db = new ConciseDb()
  // Method db.init should be called after initing the class
  // And should use await to wait this function complete
  // Of course, using .than instand of await is okay
  await db.init<Database>(adapter, init)

  db.data.test.push(1)

  // db.getData() remains a synchronous method
  console.log(db.data, db.getData()) // Output: { test: [ 1 ] } { test: [ 1 ] }

  // Try modifying the content of db.json
  setTimeout(async () => {
    await db.read()
    console.log(db.data) // Output: Depends on what you modified
  }, 10000)
})()

Advanced usage

Make your own adapter

Abstract class you need to extends

  • Synchronization
/**
 * Adapter for synchronous storage
 */
export abstract class AdapterSync<T extends object, R> {
  public adapterOptions: R
  constructor(adapterOptions: R) {
    this.adapterOptions = adapterOptions
  }

  /**
   * Write data
   * @param data the data should be written
   * @returns whether the write is successful
   */
  public abstract write(data: T): boolean
  /**
   * Read data
   * @returns
   *  If you return string, ConciseDb will help you try parsing it to T.
   *  If you return false, it means there may be something wrong with the storage or non-exist.
   *  If you return T (typeof T is object), ConciseDb will use it as the data directly.
   */
  public abstract read(): T | false | string
}
  • Asynchronization
/**
 * Adapter for asynchronous storage
 */
export abstract class Adapter<T extends object, R> {
  public adapterOptions: R
  constructor(adapterOptions: R) {
    this.adapterOptions = adapterOptions
  }

  /**
   * Write data
   * @param data the data should be written
   * @returns whether the write is successful
   */
  public abstract write(data: T): Promise<boolean>
  /**
   * Read data
   * @returns
   *  If you return string, ConciseDb will help you try parsing it to T.
   *  If you return false, it means there may be something wrong with the storage or non-exist.
   *  If you return T (typeof T is object), ConciseDb will use it as the data directly.
   */
  public abstract read(): Promise<T | false | string>
}

Example:

  • Synchronization
import { AdapterSync } from 'concisedb'

interface TestAdapterSyncOptions {
  readType: number
}

/**
 * Test adapter
 */
export default class TestAdapterSync<T extends object> extends AdapterSync<T, TestAdapterSyncOptions> {
  private _data: T
  private readType: number
  constructor(options: TestAdapterSyncOptions, defualtData: T) {
    super(options)
    this._data = defualtData
    this.readType = options.readType
  }

  public read(): T | false | string {
    if (this.readType === 1)
      return false
    else if (this.readType === 2)
      return this._data
    else if (this.readType === 3)
      return JSON.stringify(this._data)
    else if (this.readType === 4)
      return '123'
    else
      return false
  }

  public write(_data: T): boolean {
    return Math.floor(Math.random() * (264 - 1 + 1) + 1) % 2 === 0
  }
}
  • Asynchronization
import { Adapter } from 'concisedb'

interface TestAdapterOptions {
  readType: number
}

/**
 * Test adapter
 */
export default class TestAdapter<T extends object> extends Adapter<T, TestAdapterOptions> {
  private _data: T
  private readType: number
  constructor(options: TestAdapterOptions, defualtData: T) {
    super(options)
    this._data = defualtData
    this.readType = options.readType
  }

  public async read(): Promise<T | false | string> {
    if (this.readType === 1)
      return false
    else if (this.readType === 2)
      return this._data
    else if (this.readType === 3)
      return JSON.stringify(this._data)
    else if (this.readType === 4)
      return '123'
    else
      return false
  }

  public async write(_data: T): Promise<boolean> {
    return Math.floor(Math.random() * (264 - 1 + 1) + 1) % 2 === 0
  }
}

Synchronization adapters use ConciseDbSync to init

Asynchronization adapters use ConciseDb to init

Version choose: v0 and v1

concisedb has two main versions now. Below are their example codes.

They all support async APIs

  • v0:
const ConciseDb = require('concisedb')
const path = require('path')

const db = new ConciseDb(path.join(__dirname, 'db.json'), { test: [] })

db.data.test.push(1)

console.log(db.data) // Output: { test: [ 1 ] }
  • v1:
const ConciseDbSync = require('concisedb').ConciseDbSync
const JSONAdapterSync = require('concisedb').JSONAdapterSync
const path = require('path')

const adapter = new JSONAdapterSync({
  filePath: path.join(__dirname, 'db.json')
})

// Adapter, Default data (optional), Whether realtime update is needed (default: true)
const db = new ConciseDbSync(adapter, { test: [] })

db.data.test.push(1)

console.log(db.data) // Output: { test: [ 1 ] }

So v1 allows you to use adapter to store in different places.

However, v0 will still be maintained by the author.

View branch v0 on GitHub