simple to use nedb cache layer with restful api routing

restify-nedb (for nedb)  

restify-nedb was built to give you restful api resources for client side application frameworks like angular.js, ember.js, backbone.js or knockout.js as well as give you a simple file/memory based cache utilizing nedb. (ps, i love nedb, you should too.) If you haven't already checked it out, maybe you want to use it separate of all of this extra stuff, do it. It's like sqlite, with a subset of mongodb's api. Really neat.

  • Let me know if you have any issues, please open issues/prs etc, it's a lot more fun that way
  • There's still a good chunk of the nedb api I need to wrap in, if you need the core crud stuff, this should work well for you
  • I'd like to point out there coule be a few rough parts, but it's coming along.
  • Super fast nedb file/memory backed cache w/ simple garbage collection
  • 100% coffeescript, hate it or love it
  • restful routing: GET, POST, PUT, DELETE
  • parses json/multi-part
npm install restify-nedb --save
  /* example in .js */
var express = require('express');
var app = express();
var restify = require('restify-nedb').mount;
var config = require('restify-nedb').config;
var sampleMiddleware = function (reqresnext) {
  console.log('here\'s a sample middleware...');
  return next();
// default config options 
var opts = {
  filePath: __dirname + '/db/filestore.db',
  maxAge: 1000 * 60 * 60,
  prefix: '/session',
  middleware: [sampleMiddleware]
// initialize our config object 
cfg = new config(opts);
// if you aren't already using an nedb 
// instance, then calling this will create 
// one for you. 
// builds routes 
api = new restify(cfg, app);

express = require "express"
app = module.exports = express()
restify = require("restify-nedb").mount
config = require("restify-nedb").config
sampleMiddleware = (req, res, next) ->
  console.log "here's a sample middleware..."
opts = 
  maxAge: 1000 * 60 * 60
  prefix: "/session"
  middleware: [sampleMiddleware]
cfg = new config opts
# if you aren't already using an nedb 
# instance, then calling this will create 
# one for you. 
# builds routes 
api = new restify cfgapp
Step 3) Submit bugs and nasties here.
dsinternalDataStoreallow for outside nedb processes to be restified. tip: config.ds() returns a new DataStore with whatever your opts are set to, once it's fired it will internalize and share
prefix/dsStringdefines the first route path, for instance http://localhost:3000/ds
version/v1Stringnot preferred, as a rule i feel these aren't the best idea for your api, last thing you want is fragmentation in your api
exclude[]Arrayexcludes keys/values from the api, good for things like password
middleware[]Arraymiddlewares, ie passport authentication, logging, analytics
memoryStorefalseBooleanwhether or not keep an in-memory store or a file based persistant store, defaults to false, we like persistant files.
fileNamenedb-filestore.dbStringfile name for your nedb filestore
filePath../dbStringbit easier to change the path and view the contents instead of digging through node_modules
maxAge1000 * 60 * 60Numberif set to null or false automated gc will be disabled
storeundefinedStringnot currently working - will allow for multiple nedb collections, still working out the kinks.
GET http://localhost:3000/session/v1
POST http://localhost:3000/session/v1
GET http://localhost:3000/session/v1/:id
PUT http://localhost:3000/session/v1/:id
DELETE http://localhost:3000/session/v1/:id
GET http://localhost:3000/session/v1?id=:id
PUT http://localhost:3000/session/v1?id=:id
GET http://localhost:3000/session/v1?limit=20
GET http://localhost:3000/session/v1?skip=10
GET http://localhost:3000/session/v1?sort=val
GET http://localhost:3000/session/v1?sort=-val
GET http://localhost:3000/session/v1?key=value
PUT http://localhost:3000/session/v1/:id?append=true
  • append defaults to false. Set to true to do something similar to findAndUpdate
POST http://localhost:3000/session/v1
  • _stale in your body/json will act as an override to stale, say you need some things to last longer/shorter than other cached items
mocha test\ -R spec --compilers coffee:coffee-script
  • I would recommend using something like Advanced REST Client for testing, it'll help.
  • If you want upto date / latest documentation run cake docs, this way if I forget, you can easily skim thru the source -- /docs should be included.

The MIT License (MIT)
Copyright (c) 2013 David Higginbotham 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.