Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js to Node.js communication

How can I use the modules loaded from other Node process from another Node process.

Example I run:

node my_modules

which load MyModule

then I will run another nodejs process:

node grab_modules

which will run GrabModule

GrabModule will attempt to use the functions inside MyModule

Is this possible? And if this is possible how?

like image 329
Richeve Bebedor Avatar asked Jun 04 '12 06:06

Richeve Bebedor


1 Answers

What you want is probably dnode:

From the README of dnode:

The server (which hosts the functions to be run):

var dnode = require('dnode');

var server = dnode({
    zing : function (n, cb) { cb(n * 100) }
});
server.listen(5050);

The client (which calls functions on the server and gets their results in a callback)

var dnode = require('dnode');

dnode.connect(5050, function (remote) {
    remote.zing(66, function (n) {
        console.log('n = ' + n);
    });
});
like image 184
Gjorgi Kjosev Avatar answered Oct 10 '22 15:10

Gjorgi Kjosev