CoffeeScript in ArangoDB: Feature Preview | ArangoDB 2013
In my blog post about npm packages, I tried to use underscore for ArangoDB. I found that the easiest way to archive this, is using the nodes package manager NPM. Node packages and modules follow the Common.JS specification, so they can be used by ArangoDB.
Why not try to use the package coffee-script as well? Install it using
npm install coffee-script
and that’s it. Unfortunately, CoffeeScript use a module “path”, which is not a CommonJS module. I assume that most of the functionality is part or will be part of the module “fs”. The “path.js” from node.js is simple JavaScript code with some references like
'path.exists is now called `fs.exists`'
Being brave, I simply copied the file into my module path and tried again. The next obstacle is node’s global variable “process”. Luckily, this is only used to check for Windows in the module “path”. Also ignoring the module “vm” used to execute JavaScript code, this allows one to actually load CoffeScript into ArangoDB.
arangosh> process = {};
{ }
arangosh> var cs = require("coffee-script");
arangosh> cs.compile("a = 1\nopposite = true\na = -a if opposite", {});
(function() {
var a, opposite;
a = 1;
opposite = true;
if (opposite) {
a = -a;
}
}).call(this);
So, I can now use CoffeeScript definition within ArangoDB. Some of the loaders must be adjusted to check for both “.js” and “.coffee” files. Afterwards it should be possible, to define an action in CoffeeScript as well as JavaScript.
2 Comments
Leave a Comment
Get the latest tutorials, blog posts and news:
This sounds superawesome!! Is native coffeescript support out-of-the-box planned? Being able to write my actions in plain coffeescript would certainly make my day, every day!
I think, it should be very easy to add – once the general problems (like a global “process” object) have been sorted out. So, the answer is “yes”.