Node.js should not be compared to Narwhal. Instead it should be compared to Rhino. Like Rhino, Node.js is a JavaScript interpreter.
Node.js conforms to the CommonJS specification for modules, so all libraries for it are CommonJS compatible. It looks like Narwhal is also CommonJS compatible which would mean that they would be usable in Node.js.
But first look at Node.js's standard modules since there seems to be a lot of overlap there with Narwhal. Also, have a look at the list of third-party modules available for Node.js: http://github.com/ry/node/wiki/modules
Additional answer:
Ah, I see now. Narwhal is indeed like Node.js. You said that Narwhal is a framework which threw me off. I see now that it is not. Indeed, the intro page says that you can run frameworks like Nitro on top of the Narwhal interpreter.
The difference between Narwhal and Node.js is basically Narwhal uses a pluggable JavaScript engine architecture while Node.js just uses V8. Both are JavaScript "shells" proper (let’s call them that for now to avoid confusion with the term "interpreter").
I'm not sure how far one can take CommonJS libraries written for either platform and use it on the other platform. I would guess certainly all the pure-JavaScript libraries are cross compatible. Node.js does use a nonblocking I/O model, so some binary modules for Narwhal may not work correctly on Node.js.
Node.js does stress callback style programming though (to make maximum use of nonblocking I/O). For a seasoned JavaScript programmer this is not an issue since we're used to setTimeout()
, XMLHttpRequest
etc. In fact, as a seasoned JavaScript programmer, I sort of prefer Node.js's style. Narwhal feels too much like C.
Examples:
Here's what I mean by the different "feel" of Node over Narwhal.
In Narwhal, the example for slurping a file is:
var fs = require("file");
var data = fs.read(myfilename); /* Code stops at this point
* until all data is read
*/
/* Process data here */
In Node.js it is:
var fs = require('fs');
fs.readFile(myfilename, function(err,data) {
/* Process data here */
});
/* readFile returns immediately and code continues
* executing while file is being read
*/
Just like setTimeout
, reading files in Node.js is asynchronous (your code need to wait for the hard disk to seek and read data during which time you can run other pieces of code).