Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In nodeJs socket.io on method is unresolved in webstorm

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');
});

enter image description here

but webstorm is saying that 'on' is unresolved .. please help

like image 486
user6554563 Avatar asked Oct 08 '16 08:10

user6554563


3 Answers

  1. Open 'Settings' in WebStorm (Ctrl+Alt+S)
  2. Go to 'Languages & Frameworks' → 'JavaScript' → 'Libraries'
  3. Press 'Download'
  4. Select the libriary 'socket.io'
  5. Press 'Download and install'

That's all folks!

like image 149
Pax Beach Avatar answered Oct 19 '22 05:10

Pax Beach


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>
like image 39
Anshuman Singh Avatar answered Oct 19 '22 06:10

Anshuman Singh


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>
like image 24
user6554563 Avatar answered Oct 19 '22 07:10

user6554563