Answer the question
In order to leave comments, you need to log in
Why does koa + socket.io throw an error - TypeError: Class constructor Application cannot be invoked without 'new'?
const
http = require('http'),
koa = require('koa'),
app = koa(),
serve = require('koa-static'),
server = http.createServer(app.callback()),
io = require('socket.io')(server);
app.use(serve('./public'));
io.on('connection', function (socket) {
socket.on('click', function (data) {
//process the data here
console.log('client clicked! data:');
console.log(data);
// emit an event
console.log('responding with news');
socket.emit('news', { hello: 'world' });
});
});
var port = process.env.PORT || 3000;
server.listen(port);
console.log ('Listening at port ' + port + ' ...');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question