ArangoDB 3.12 Product Release Announcement! Read the blog for details. Read Blog

Vector-5

Feature Preview: Using NPM packages for ArangoDB

Estimated reading time: 1 minutes

ArangoDB follows the Common.JS specification for modules. However, it would be very convenient, if there was an easy way to install a package like “underscore.js”. These package are, for instance, available using NPM. There is a draft for packages on Common.JS which seems to be compatible with NPM.

NPM has a neat way of dealing with version conflicts. Basically, it allows multiple versions to exists simultaneously. For example, assume you have 4 packages A, B, C, D. A requires B and C and D, B requires C. Then directory layout might be as follows.

node_modules
|
+- A
|  |
|  +- node_modules
|     |
|     +- B
|     |  |
|     |  +- node_modules
|     |     |
|     |     +- C (1.0.0)
|     |
|     +- C (2.0.0)
|
+- D

Package B will see package C in version 1.0.0, while package A sees package C in version 2.0.0.

                                                                                                                                    <!--more-->

This behaviour is easy to implement in ArangoDB. In addition to “Module” there is now a “Package”. Each package has it own module cache. When a package requires a module, the package hierarchy is traversed from the current package to the root (or global) package, until the module is found.

In order to use underscore, switch into the package directory and use NPM to install it

unix> cd /tmp/packages
unix> npm install underscore
npm http GET https://registry.npmjs.org/underscore
npm http 304 https://registry.npmjs.org/underscore
underscore@1.4.4 node_modules/underscore

Now start arangosh with the new “–javascript.package-path” option and enjoy underscore.

unix> arangosh --javascript.package-path /tmp/packages
arangosh> var _ = require("underscore");
arangosh> _.max([1,2,3])
3
Picture of Frank Celler
February 27, 2013 ,

Frank is both entrepreneur and backend developer, developing mostly memory databases for two decades. He is the CTO and co-founder of ArangoDB. Try to challenge Frank asking him questions on C, C++ and MRuby. Besides Frank organizes Cologne’s NoSQL group & is an active member of NoSQL community.

Leave a Comment