If you don't want to use socket.io
, but the websocket package, you can use it in combination with Express like this:
// app.js
var WebSocketServer = require('websocket').server;
var express = require('express');
var app = express();
var server = app.listen(8888);
var wsServer = new WebSocketServer({ httpServer : server });
// this will make Express serve your static files
app.use(express.static(__dirname + '/public'));
// the rest of your code
wsServer.on('request', function(r) { ...
express.static
will take care of serving your HTML/CSS/JS files. The argument you pass is the directory where those files are located (in this case, the directory public/
relative to where app.js
is located).