I'm trying to migrate a service from nodejs to ringojs. I've run into a problem with using require(). For example
consider this:
var restify = require('restify');
RingoJS cannot find the restify module because it doesn't know to look
in the node_modules directory. I can add node_modules to the path that RingoJS uses
(and I did), but that doesn't help when restify calls require(),
because the modules are nested in the directory tree.
Is there a way to get RingoJS to look for required modules in the node_modules directory?
You can add additional directories to Ringo's module search path with the
-moption. Example: Installunderscorevia npm withnpm install underscoreand start ringo withringo -m ./node_modules yourscript.js. Undersocre will be available and can be required as expected:Your specific problem seems to be that restify is only compatible with Node.js and not with other CommonJS-like platforms. It might have some sub-modules compatible with Ringo, but I haven't found any so far. Ringo's
package.jsonis not 1:1 compatible with Node's / npm'spackage.json. If restify uses some Node-specific stuff in the package descriptor, Ringo cannot load these resources.Ringo is still very close to ideas behind CommonJS with its various standardized modules, whereas Node has left this path a long time ago. You find CommonJS modules (which use
require()to load a module) in Node, but not the different other APIs CommonJS tried to establish for server-side JavaScript.Also, Ringo is not built around callbacks / an event-driven non-blocking I/O. You can use non-blocking I/O on Ringo, but you also can stick with blocking I/O. This is different with Node.js, where you have to develop in a non-blocking way and everything is optimized to run smooth with the event-driven model.