Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Very simple file wrapper to GET, PUT and DELETE javascript objects to files.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
Gruntfile.js
index.js
licence-mit.txt
package.json
readme.md

readme.md

json-file-db

What?

Very simple file wrapper to GET, PUT and DELETE javascript objects to files to use with Node.JS.

Why?

Good in the first spins of your project when you still don't need a real Db and just want to save docs to a file.

Install

npm install json-file-db

API

Save a document

var openDB = require('json-file-db');
var db = openDB('file.json');

db.put({id=12, data="someData"}, function(err){

});

Get all documents

var openDB = require('json-file-db');
var db = openDB('file.json');

db.get(function(err, data){
  console.log(data.length);
});

Get documents matching a query (using _.where())

var openDB = require('json-file-db');
var db = openDB('file.json');

db.get({name:"mike", age:10}, function(err, data){
  console.log(data.length);
});

Get documents matching an Id value

var openDB = require('json-file-db');
var db = openDB('file.json');

db.get(10, function(err, data){
  console.log(data.length);
});

Get a single document

This is a thin wrapper around get() to avoid checking for data.length before accessing data[0].

var openDB = require('json-file-db');
var db = openDB('file.json');

db.getSingle(10, function(err, data){
  console.log(data.name);
});

Delete a document

var openDB = require('json-file-db');
var db = openDB('file.json');

db.delete(10, function(err, data){
  console.log(data.Name);
});

What else?

  • The module is not optimized. Files are read and written completly on each operation.
  • It's got unit tests. run mocha to run them

Licence

MIT (see licence-mit.txt)

Something went wrong with that request. Please try again.