Very simple file wrapper to GET, PUT and DELETE javascript objects to files to use with Node.JS.
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.
npm install json-file-db
var openDB = require('json-file-db');
var db = openDB('file.json');
db.put({id=12, data="someData"}, function(err){
});
var openDB = require('json-file-db');
var db = openDB('file.json');
db.get(function(err, data){
console.log(data.length);
});
var openDB = require('json-file-db');
var db = openDB('file.json');
db.get({name:"mike", age:10}, function(err, data){
console.log(data.length);
});
var openDB = require('json-file-db');
var db = openDB('file.json');
db.get(10, function(err, data){
console.log(data.length);
});
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);
});
var openDB = require('json-file-db');
var db = openDB('file.json');
db.delete(10, function(err, data){
console.log(data.Name);
});
- The module is not optimized. Files are read and written completly on each operation.
- It's got unit tests. run
mocha
to run them
MIT (see licence-mit.txt)