Sep 9, 2018 · 1 min read
I you want to use 'express' instead of the 'http' module, you can include the following code:
const PORT = 3000;
const ws = require(`websocket`);
const WebSocketServer = ws.server;
const express = require('express');
const app = express();
const http = require('http').Server(app);
/**
* Express Server
*/
app.use('/', express.static('public'));
http.listen(PORT, function () {
console.log(new Date() + " Server is listening on port: " + PORT);
});
const wsServer = new WebSocketServer({
httpServer: http
});