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 conform 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.
But first look at Node's standard modules since there seem to be a lot of overlap there with Narwhal. Also, have a look at the list of 3rd party modules available for Node.js: http://github.com/ry/node/wiki/modules
Additional answer:
Ah, I see now. Narwhal is indeed like Node. 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 is basically Narwhal uses a pluggable javascript engine architecture while Node just use V8. Both are javascript "shells" proper (lets 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-JS libs are cross compatible. Node does use a nonblocking I/O model so some binary modules for Narwhal may not work correctly on Node.
Node does stress callback style programming though (to make maximum use of nonblocking I/O). For a seasoned JS programmer this is not an issue since we're used to setTimeout()
, XMLHttpRequest
etc. In fact, as a seasoned JS programmer, I sort of prefer Node'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 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).