We have our client-side code ready to make WebSocket requests; now we can move on to our Node backend. First, we'll need to set up our Socket.IO middleware. There is a small caveat to this, in that we cannot use Socket.IO as a middleware of the Express application directly, since Socket.IO expects a Node.js HTTP server and has no direct support for Express. Instead, we'll create a web server using the built-in Node.js HTTP module, passing our Express application as
. We can then use the
listen function in Socket.IO to connect to the server.
The following is how the code looks in our
express = require 'express' path = require 'path' app = express() server = (require 'http').createServer app ...