i am trying to use node.js v0.8.2 and the cluster functionality to set up a web server on each core of my quad core machine
however i am stuck on a TypeError: Object is not a function, i am sure this is a simple error.
what am i doing wrong.
this is the code i am using
var cluster = require('cluster')
, http = require('http');
var server = http.createServer(function(req, res){
console.log('%s %s', req.method, req.url);
var body = 'Hello World';
res.writeHead(200, { 'Content-Length': body.length });
res.end(body);
});
cluster(server)
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.pidfiles('pids'))
.use(cluster.cli())
.use(cluster.repl(8888))
.listen(3000);
this is the erorr
F:\nodeJS\module\one.js:11
cluster(server)
^
TypeError: object is not a function
at Object. (F:\nodeJS\module\one.js:11:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
It looks like you're trying to use the old Cluster module from LearnBoost. Since that module was released, cluster
is now the name of a core module in Node.js, and using require('cluster')
will always return the core module. See LearnBoost/cluster issue #166 for more information.
Looks like you are over-complicating the use of cluster... try this instead:
var cluster = require('cluster')
if ( cluster.isMaster ) {
for ( var i=0; i<2; ++i )
cluster.fork();
} else {
// includes for your app and app controller logic here (just example using express, etc)
///////////////////
// Server initiation
///////////////////
var app = require('express').createServer(),
redis = require("redis"),
Step = require("step"),
client = redis.createClient(siteConf.redisPort, siteConf.redisHost);
// rest of your app here
}