I am learning socket.io in node and i have installed the module using-
npm install socket.io --save
here is my code
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.send('index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
but webstorm is saying that 'on' is unresolved .. please help
That's all folks!
Try -
var io = new require('socket.io')(http);
and make sure you are including this script on client side
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
</script>
I did not include this script on client side that is why
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With