Giter VIP home page Giter VIP logo

changes-loader's Introduction

changes-loader

Store CouchDB _changes handlers in your design docs and have Node.JS execute them.

Setup dependencies

You'll need felixge's node-couchdb library:

mkdir -p ~/.node_libraries/
git clone git://github.com/felixge/node-couchdb.git ~/.node_libraries/node-couchdb

Run the changes-loader.js script

Keep the changes-loader.js script running:

node /path/to/changes-loader.js [COUCHDB_ROOT_URL]

This script looks through all databases for any design docs with _changes handlers code to be loaded and run. New databases will be detected every 60 seconds.

The COUCHDB_ROOT_URL argument defaults to http://localhost:5984

(TODO: include example Upstart and launchd scripts)

Define _changes handlers

Each design document can define any number of _changes handlers by having a property off the root of the object called "changes":

{
  "views": { ... },
  "lists": { ... },
  "changes": {
    "foo": function(change) {
      // Respond to changes here...
    },
    "bar": function(change) {
      // Do other stuff here...
    }
  }
}

Note that in this example "foo" and "bar" are the names of two different changes handlers defined by this design document.

Changes handler context

From your _changes handler, you'll have access to the following objects:

  • db — the database that host the loaded changes function (from felixge's node-couchdb)
  • ddoc — the design document that hosts the loaded changes function
  • log(msg) — this will show up in the stdout of the changes-loader.js script
  • require(moduleID) — load CommonJS modules, as follows:
    • if the moduleID begins with ./ or ../ load a module from the design document
    • otherwise Node.JS will load the module from its require() paths

Node.JS compatibility

This code has been known to work with version 0.1.91 of Node. As always, YMMV (^_-)

changes-loader's People

Contributors

zdzolton avatar

Stargazers

 avatar Geoff Buesing avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.