JSON Filesystem Database

1.0.3 · abandoned · verified Wed Apr 22

JSON FileSystem Database (jsondbfs) is a NoSQL document database, analogous to MongoDB, designed for Node.js environments. The latest version, 1.0.3, was released in 2017, and the project appears to be no longer actively maintained. It offers fully asynchronous data operations, leveraging the `async` library for parallel execution of accessing and filtering data. It supports two primary drivers: a high-performance 'Memory' driver, which can be configured to periodically flush data to disk for persistence, and a 'Disk' driver that stores all data directly on the filesystem and implements pessimistic transaction locking for data integrity. The package provides a lightweight, file-based database solution with Mongo-style query capabilities via `json-criteria`, but its lack of ongoing development means it may not be suitable for new projects or environments requiring up-to-date dependencies or security patches.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a JSON DB FS instance, create/access collections, and perform common CRUD operations (insert, count, update, find, remove) using the asynchronous callback API.

const jsondbfs = require('jsondbfs');
let database;

// Connect to the database, specifying collections and configuration
jsondbfs.connect(['Users', 'Products'], { path: './data', driver: 'memory' }, function(err, db){
  if (err) return console.error('Connection error:', err);
  database = db;
  console.log('Database connected. Current collections:', Object.keys(database));

  // Insert a document into the 'Users' collection
  database.Users.insert({ name: 'Alice', email: 'alice@example.com', roles: ['User'] }, function(err, document){
    if (err) return console.error('Insert error:', err);
    console.log('Inserted document:', document);

    // Count documents in 'Users' collection
    database.Users.count(function(err, count){
      if (err) return console.error('Count error:', err);
      console.log('Total users:', count);

      // Update a document
      database.Users.update({ name: 'Alice' }, { email: 'alice.updated@example.com' }, function(err, result){
        if (err) return console.error('Update error:', err);
        console.log('Update result:', result);

        // Find all documents matching a criteria
        database.Users.find({ email: 'alice.updated@example.com' }, function(err, documents){
          if (err) return console.error('Find error:', err);
          console.log('Found documents:', documents);

          // Remove a document
          database.Users.remove({ name: 'Alice' }, function(err, success){
            if (err) return console.error('Remove error:', err);
            console.log('Document removed:', success);

            // Count again after removal
            database.Users.count(function(err, finalCount){
              if (err) return console.error('Final count error:', err);
              console.log('Users after removal:', finalCount);
            });
          });
        });
      });
    });
  });
});

view raw JSON →