Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a function as a separate node.js process?

Is it possible to run a function as a completely separate node.js process? For example:

var parallel = require("parallel");
parallel(function(){
    var app = require("express")();
    app.on("/",function(req,res){ res.send("hi"); });
    app.listen(80);
},function callback(err,stdout){
    console.log("process terminated!")
});

Is something like that possible?

like image 355
MaiaVictor Avatar asked Nov 12 '22 08:11

MaiaVictor


1 Answers

First off, try to use the idiomatic way of load-balancing. For node, this is asynchronous design. See these other answers for more info:

  • https://stackoverflow.com/a/8685968/538551
  • https://stackoverflow.com/a/11278689/538551

There are options though:

  • threading: threads_a_go_go (source on github).
  • fibers: node-fibers
    • note, this only does concurrency, not parallism; it's more for code structure than parallel processing (more here)
  • apache thrift nodejs plugin: not directly what you're asking for, but this is the route I'd go. I'd implement the hard stuff in something low-level (like C)
like image 62
beatgammit Avatar answered Nov 14 '22 22:11

beatgammit