server.js
var http = require(“http”); var url = require(“url”); var fs = require(“fs”); function start(pages, port) { function onRequest(request, response) { fs.readFile(__dirname+"/"+pages,function(err,data){ if(err){ response.writeHead(500); } response.writeHead(200, { “Content-Type”: “text/html” }); response.end(data); }) } http.createServer(onRequest).listen(port) console.log(“Server has started.”); } exports.start = start;
app.js
var server = require("./server"); server.start(“index.html”, 8888); var io = require(“socket.io”).listen(server)