0.0.2 • Published 11 years ago

nodejs4xpcom v0.0.2

Weekly downloads
7
License
-
Repository
github
Last release
11 years ago

nodejs4xpcom (n4x)

nodejs4xpcom (or n4x) is an XPCOM plugin (for Firefox, Thunderbird, etc) that provides an AMD-compatible Node.JS module loader.

Usage

First, this plugin must be installed in the XPCOM application (Firefox, Thunderbird, etc). Then, the following code snippet will allow you to require or define dependencies to Node.JS modules that have been installed into the standard npm node_modules directory.

For example, the following makes use of the underscore module:

Components.utils.import("resource://n4x/modules/nodejs.jsm");
let require = nodejs.make_require(__LOCATION__);
let _ = require('underscore');
let squares = _.map([3, 6, 12], function(i){ return i*i; }));
// result: squares == [9, 36, 144]

Limitations

n4x loads Node.JS modules as if they were standard JavaScript scripts. Many modules, however, make use of other modules that are provided by the Node.JS environment, such as fs and util, and therefore cannot be loaded by XPCOM. In order to provide that functionality, an adapter for each of those system modules must be created. Here is a summary of that effort for each of the system modules for Node.JS version 0.8.17:

ModuleSupportModuleSupportModuleSupportModuleSupport
assert20%fs0%process0%tls0%
buffer0%globals10%punycode0%tty0%
child_process0%http0%querystring0%dgram0%
cluster0%https0%readline0%url0%
crypto0%modules0%repl0%util0%
dns0%net0%stdio10%vm0%
domain0%os0%stream0%zlib0%
events0%path0%string_decoder0%

These adapter packages will be implemented on an as-needed by the maintainers basis; if you need one before we do, you are encouraged to implement it and issue a pull-request: these will be accepted quickly.