ArangoDB

JavaScript Modules

The ArangoDB uses a CommonJS compatible module concept. You can use the function require in order to load a module. require returns the exported variables and functions of the module. You can use the option startup.modules-path to specify the location of the JavaScript files.


  1. require


require(path)
require checks if the file specified by path has already been loaded. If not, the content of the file is executed in a new context. Within the context you can use the global variable exports in order to export variables and functions. This variable is returned by require.

Assume that your module file is test1.js and contains

exports.func1 = function() {
  print("1");
};

exports.const1 = 1;

Then you can use require to load the file and access the exports.

> ./arangod --shell --startup.modules-path "/tmp/path1;/tmp/path2" /tmp/vocbase
ArangoDB shell [V8 version 3.6.5.1, DB version 1 (9727)]

arango> var test1 = require("test1");

arango> test1.const1;
1

arango> test1.func1();
1

require follows the specification Modules/1.1.1.