From f7990279c2a45358df31ebd6ca5b94be0e6524aa Mon Sep 17 00:00:00 2001 From: Fabio Cirone Date: Wed, 20 Jul 2016 17:17:55 -0300 Subject: [PATCH] testing http server --- index-http-server.js | 24 ++++++++++++++++++++++++ package.json | 1 + 2 files changed, 25 insertions(+) create mode 100644 index-http-server.js diff --git a/index-http-server.js b/index-http-server.js new file mode 100644 index 0000000..6150ca7 --- /dev/null +++ b/index-http-server.js @@ -0,0 +1,24 @@ +var cluster = require("cluster"); +var http = require("http"); +var numCPUs = require("os").cpus().length; +var port = 8888; + +if (cluster.isMaster) { + for (var i = 0; i < numCPUs; i++) { + cluster.fork(); + } + + cluster.on('online', function(worker) { + console.log('Worker ' + worker.process.pid + ' is online'); + }); + + cluster.on("exit", function(worker, code, signal) { + cluster.fork(); + }); +} else { + http.createServer(function(request, response) { + console.log("Request for: " + request.url + " on process " + process.pid); + response.writeHead(200); + response.end("hello world\n"); + }).listen(port); +} diff --git a/package.json b/package.json index a463fee..13fde34 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "blitzkrieg": "^1.0.0", "crypto": "0.0.3", "express": "^4.14.0", + "http": "0.0.0", "throng": "^4.0.0" } }