Thanks to node.couch.js, I think I have finally exhausted the subject of the CouchDB changes API. Interesting stuff, especially coupled with node.js. At this point, I think I am just about ready to get started with actual work on my chain's purpose (a mechanism for maintaining recipes from last year's chain). But before I do...
I think I will spike on node.couchapp.js. Node.couchapp.js is aiming to be a couchapp implementation in node.js. I have no idea how complete an implementation it is, but it has one major advantage in my eyes over couchapp: it's written in javascript/node.js vs. python.
I clone the repository:
cstrom@whitefall:~/repos$ git clone git://github.com/mikeal/node.couchapp.js.gitIt takes me a little bit of rooting about, but I finally determine that the script that needs to be executed is
Initialized empty Git repository in /home/cstrom/repos/node.couchapp.js/.git/
remote: Counting objects: 70, done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 70 (delta 22), reused 0 (delta 0)
Receiving objects: 100% (70/70), 14.81 KiB, done.
Resolving deltas: 100% (22/22), done.
lib/bin.js
:cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -hThe entire package appears to be installable via something called NPM (Node.js package Manager). I opt to avoid this (for now) as it seems to be very much a work in progress. Besides I am able to get the help output described in the node.couchapp.js README without NPM installation.
Invalid Option: -h
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js help
-d, --design :: File or directory for design document(s)
-t, --test :: Run tests.
-s, --sync :: Sync with CouchDB.
-c, --couch :: Url to couchdb.
At this point, I am very much flying blind. I do not know which, if any of those options are required. I am not sure what the format of the design documents should be. I am not entirely clear what
--sync
should do, though I'd guess that it is analogous to couchapp's "push".Well, what happens when I run the command without any options:
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.jsHmm... It would seem nothing. A quick scan of the CouchDB log confirms this.
cstrom@whitefall:~/tmp/test_node_couchapp_js$
What happens when I supply a CouchDB url?:
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -c http://localhost:5984/seedNothing again.
cstrom@whitefall:~/tmp/test_node_couchapp_js$
Well what happens when I supply an empty design document directory along with a CouchDB URL?
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -d . -c http://localhost:5984/seedHrm... Well how about an empty dot-JS file?
Error: Cannot find module '/home/cstrom/tmp/test_node_couchapp_js'
at loadModule (node.js:574:15)
at require (node.js:700:12)
at Object.<anonymous> (/home/cstrom/repos/node.couchapp.js/lib/bin.js:22:16)
at Module._compile (node.js:721:23)
at node.js:749:20
at fs:51:23
at node.js:810:9
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -d foo.js -c http://localhost:5984/seedBack to nothing.
cstrom@whitefall:~/tmp/test_node_couchapp_js$
Perhaps I need to tell it to sync?
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -d foo.js -c http://localhost:5984/seed -sAh, now we're getting somewhere.
No design docs in provided modules!
After a little fiddling around, I create a "design document" that looks like this:
{Even with that, I still get:
show: "function() { return 'foo'; }"
}
cstrom@whitefall:~/tmp/test_node_couchapp_js$ cat foo.jsI have to call it a night at this point. Hopefully I will be able to make more progress on this tomorrow.
{
show: "function() { return 'foo'; }"
}
cstrom@whitefall:~/tmp/test_node_couchapp_js$ node ~/repos/node.couchapp.js/lib/bin.js -s -d foo -c http://localhost:5984/seed
No design docs in provided modules!
Day #70
if you are hacking on this, I'd really like to see Node.js code that can push existing CouchApp source trees to CouchDB.
ReplyDeleteMikeal's node library has some cool features, but isn't aiming for direct interoperability with the filesystem format. Which is cool. But I'd also be really excited to see a node js version of couchapp.py
Here are some example apps that written for node.couchapp.js
ReplyDeletehttp://github.com/mikeal/js-registry/blob/master/app.js
http://github.com/mikeal/relaximation/blob/master/graphsapp/app.js
@jchris I don't know that I'd really need that kind of interop. Still, seems like a good challenge, so who knows?
ReplyDelete@mikeal Thanks a ton. Those examples *really* helped the next night!