ArangoDB Client for nodejs released

API, nodejs 10 Comments

We got a note from Anders Elo from Sweden. He told us that he has released a ArangoDB client for node.js. Awesome! :-)

You can find it on Github under the URL https://github.com/kaerus/arango-client. To install locally

npm install git://github.com/kaerus/arango-client

Anders also writes:

It’s still lacking features and is prone to changes but it works quite nice, atleast I think so. :)

I’ve not documented this project as of yet due to lack of time so I’ll briefly instruct you by some examples.

var arango = require('arango.client'), util = require('util');
 
/* Prepare a connection, defaults {protocol:'http', hostname:'127.0.0.1', port: 8529} */ 
db = new arango.Connection({name:"testcollection"});
 
/* we need to first create our test collection */
db.collection.create(function(err,ret){
  console.log("err(%s): ",err, ret);
});
 
/* create a new document in collection */
db.document.create({a:"test"},function(err,ret){
  if(err) console.log("error(%s): ", err,ret);
  else console.log(util.inspect(ret));
});
 
/* create a document and a new collection on demand */
db.document.create(true,"newcollection",{a:"test"},function(err,ret){
  if(err) console.log("error(%s): ", err,ret);
  else console.log(util.inspect(ret));
});
 
/* alternate style utilizing events */
db.document.list().on('result',function(result){
  console.log(util.inspect(result));
}).on('error',function(error){
  console.log("error(%s):", error.code, error.message);
});

The interface to the ArangoDB REST api resides in the lib/api directory. You can find out more details there. Anders also includes some tests, just runt “npm test” to execute them.

Dorthe Lübbert

About Dorthe Lübbert

web developer from Cologne, interested in alternative databases & member of the ArangoDB team - mainly helping out with website and community related stuff.
  • Shekar Tippur

    I am trying to include this on a intellij project. I get this error.

    db.document.create_(“newcollection”,{a:”test”},function(err,ret){

    ^

    TypeError: Object # has no method ‘create_’

    at Object. (/Users/shekart/WebstormProjects/byeh_new/arango_conn.js:26:13)

    at Module._compile (module.js:456:26)

    at Object.Module._extensions..js (module.js:474:10)

    at Module.load (module.js:356:32)

    at Function.Module._load (module.js:312:12)

    at Function.Module.runMain (module.js:497:10)

    at startup (node.js:119:16)

    at node.js:901:3

    Process finished with exit code 8

    If I change the _create to create, I get the below message
    error(404): collection /_api/collection/newcollection not found

    I am kinda new to all this. Really appreciate any pointers.

    - Shekar

    • luebbert42

      The api for “on demand collections” has changed, I have updated the example. Hint: Anders includes many examples in the test directory of the module :-)

      • Shekar Tippur

        I have installed the latest node module.

        Here is the version info

        “name”: “arango.client”,

        “version”: “0.6.2″,

        I looked at the test folder ..
        https://github.com/kaerus-component/arango/blob/master/test/arango.js

        I see the below definition…

        var libs = [

        '../lib/arango',

        './lib/qunit-1.10.js'

        ];

        I dont see a relative folder ../lib/arango.

        And when I try to run this .. I get

        $ node arango.js

        /Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/test/arango.js:11

        module = QUnit.module;

        ^

        ReferenceError: QUnit is not defined

        I am sorry if I am posting trivial questions but I really appreciate any help.

        - Shekar

        • luebbert42

          to run the tests on a fresh node installation in the current version of arango.client I had to install two additional modules, qunit and amdefine via

          sudo npm install amdefine
          sudo npm install qunit

          • Shekar Tippur

            Here is what I see on node_modules folder ..

            $ pwd

            /Users/shekart/WebstormProjects/byeh_new/node_modules

            $ ls

            amdefine arango.client express jade qunit

            I have installed both qunit and amdefine.

            I still see the same error.

            - Shekar

          • luebbert42

            I wrote something in the Google Group (this is a bit more comfortable than the comment’s section :-))

          • Shekar Tippur

            Disqus -

            I think I got over some hiccups :).

            I believe we need var QUnit = require(‘qunit’);

            I now have new set of error:

            /usr/local/bin/node collection.js
            /Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/test/api/collection.js:19 asyncTest(‘create’,2,function(){
            ^
            ReferenceError: asyncTest is not defined
            at Object. (/Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/test/api/collection.js:19:1) at runFactory (/Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/node_modules/amdefine/amdefine.js:181:30) at define (/Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/node_modules/amdefine/amdefine.js:275:13) at Object. (/Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/test/api/collection.js:10:1) at Module._compile (module.js:456:26)
            at Object.Module._extensions..js (module.js:474:10)
            at Module.load (module.js:356:32)
            at Function.Module._load (module.js:312:12)
            at Function.Module.runMain (module.js:497:10)
            at startup (node.js:119:16)

            Process finished with exit code 8

            I tried to precede it with function asyncTest(..

            I then get a different error ..

            /Users/shekart/WebstormProjects/byeh_new/node_modules/arango.client/test/api/collection.js:19 function asyncTest(‘create’,2,function(){
            ^^^^^^^^
            SyntaxError: Unexpected string
            at Module._compile (module.js:439:25)
            at Object.Module._extensions..js (module.js:474:10)
            at Module.load (module.js:356:32)
            at Function.Module._load (module.js:312:12)
            at Function.Module.runMain (module.js:497:10)
            at startup (node.js:119:16)
            at node.js:901:3

            Any idea on whats going on?

            - Shekar

          • Loremsqlsum

            The blog is not a suitable place for Support. Please come to Google Groups.

  • Shekar Tippur

    I have installed both qunit and amdefine.

    I still see the same error.

    - Shekar

  • Shekar Tippur

    Here is what I see on node_modules folder ..

    $ pwd

    /Users/shekart/WebstormProjects/byeh_new/node_modules

    $ ls

    amdefine arango.client express jade qunit