title: socket.io TypeError: socket.on is not a function
body: <p>I am developing a node app using express which has a chatting system and I am using socket.io but I get this error</p>
  
  <pre><code>Server is listening on 3000
  made socket connection
  C:\Users\User\MyFolder\Projects\FMIS\app\app.js:139
  socket.on('chat', function(data){
         ^
  
  TypeError: socket.on is not a function
  at Namespace.&lt;anonymous&gt; 
  (C:\Users\User\MyFolder\Projects\FMIS\app\app.js:139:12)
  at emitOne (events.js:116:13)
  at Namespace.emit (events.js:211:7)
  at Namespace.emit 
  at _combinedTickCallback (internal/process/next_tick.js:131:7)
  at process._tickCallback (internal/process/next_tick.js:180:9)
  </code></pre>
  
  <p>This what I have tried to do in my `app.js</p>
  
  <pre><code>var reload = require('reload');
  var bodyParser =  require('body-parser');
  var app = express();
  var  socket = require('socket.io');
  app.set('port', process.env.PORT || 3000);
  app.set('view engine', 'ejs');
  app.set('views','app/views');
  app.locals.siteTitle = "FMIS";
  app.use(express.static('app/public'));
  
  app.use(require('./routes/Chat_api'));
  app.use(require('./routes/Chat'));
  
  var server = app.listen(app.get('port'),()=&gt;{
  console.log('Server is listening on '+ app.get('port'));
  });
  
  var io = socket(server);
  
  io.on('connection',function(){
      console.log('made socket connection');
      socket.on('chat', function(data){
          // io.sockets.emit('chat',data);
          console.log(data);
      });
  });
  reload(server, app);
  </code></pre>
  
  <p>I send and recieve data from the client like this</p>
  
  <pre><code> socket.emit('chat',{
            user: chatUsername.value,
            Message: chatMessage.value
          });
  
  socket.on('chat',function(data){
          // showMessage(data);
          console.log(data);
      });        
  </code></pre>