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)
Looks like you are over-complicating the use of cluster… try this instead: