node package manager


Stork provides a layer of document management over the CouchDB.


Stork provides a layer of document management over the CouchDB with multitenant support and the use of CouchDB view indexing to support parent/child relationships.

Inspired by resourceful.

var odm = require('stork');
var dburl = 'http://localhost:5984/stork_test'
  , User
  , BlogPost
  , Comment
User = odm.deliver('user', function() {
  this.sort('lastName', 'firstName');
  this.string('lastName', { required: true });
  this.string('email', { required: true, format: 'email' });
Comment = odm.deliver('comment', function() {
  this.string('title', { required: true });
  this.ref('author', User, { required: true });
BlogPost = odm.deliver('discussion', function() {
  this.string('title', { required: true });
  this.view('byUpdatedOn', ['updatedOn']);
  this.ref('author', User, { required: true });
  this.composes('comments', Comment);
  // DOES NOT EXIST, YET: this.method
  this.method('addComment', function (title, content, author) {
    var comment ={
          title: title
        , content: content
        , author: author
  this.method('removeComment', function (comment) {
    var childIds = {
          return child._id
      , childIndex = childIds.indexOf(comment._id)
    if (childIndex < 0) {
    this.comments.splice(childIndex, 1);
BlogPost.from(dburl).withComments(function(err, posts) {
  posts.forEach(function (post) {
    post.comments.forEach(function (comment) {
      console.log('\t', comment);

This section contains a task-based set of instructions on how to use stork for your CouchDB ODM needs. It models a simple reservation system.

Follow the instructions, below, in Installing.

Yeah, that seems pretty self evident.

var odm = require('stork');

Let's declare an entity that stork knows about. When we declare entities, we provide a name and, if we want, a function that will describe a schema for us. We can define arrays, booleans, children, date/times, numbers, objects with their own schema, references to other documents, strings, timestamps, and views.

stork uses the schema of the object to provide validation for you. You can save invalid documents to CouchDB, if you'd like. stork does not judge. stork just delivers.

var event = odm.stork('event', function() {
  this.string('name', { required: true, maxLength: 100 });
  this.string('description', { required: true });
  this.object('venue', { required: true }, function() {
    this.string('url', { format: 'url' });
    this.string('address', { required: true });
    this.string('zip', { format: /\d{5}/ });
  this.number('maximumGuests', { required: true });
  1. Make sure you have grunt-cli installed.
  2. Clone. You know how. This is GitHub, for goodness' sake.
  3. Install stuff. npm install
  4. Run the autotester. SKIP_STORK_DB_TESTS=1 ./node_modules/autotest/autotest.js --npm
  5. Or, if you want to run with db tests. ```./node_modules/autotest/autotest.js --npm``
  6. Find an issue
  7. Write a test.
  8. Write nice code.
  9. Run grunt and make sure you have no errors either in tests or in jslint.
  10. Commit.
  11. Make a PULL REQUEST if you're not already a contributor.

Because we're still developing, this ain't on npm, yet. So, right now, you can run the following commands to include it in your project.

git clone
cd stork
npm link

Read more about the npm-link command.