file-json-db

Installation

file-json-db is published on the npm registry and has zero runtime dependencies. The only requirement is a modern Node.js runtime.

Requirements

Install with npm

npm install file-json-db

Install with yarn

yarn add file-json-db

Install with pnpm

pnpm add file-json-db

Importing the library

The package is CommonJS. In a standard Node.js project you require it like this:

const { JSONDB } = require('file-json-db');

// or the default export
const JSONDB = require('file-json-db').default; // if needed
const { JSONDB } = require('file-json-db');

TypeScript

Full TypeScript declarations ship with the package (db.d.ts). You can import the types directly:

import { JSONDB, Collection, CollectionOptions, QueryBuilder, Transaction } from 'file-json-db';

const db = new JSONDB('./data');
const users = db.collection({
  name: 'users',
  autoId: true,
  indexes: ['email']
});

Manual / single-file usage

Because the library has no dependencies, you can also copy the two files into your project:

// if you copied the file into your project
const { JSONDB } = require('./lib/file-json-db');

Verify the installation

Create a small test file:

// test-install.js
const { JSONDB } = require('file-json-db');

const db = new JSONDB('./tmp-db');
const col = db.collection('smoke');

col.insert({ message: 'hello from file-json-db' });
console.log(col.findOne({ message: 'hello from file-json-db' }));
console.log('Installation OK');
node test-install.js
Tip After running the test you can safely delete the ./tmp-db folder.