text: const path = require('path');
  const http = require('http');
  const express = require('express');
  const socketio = require('socket.io');
  const {generateMessage,generateLocationMessage} = require('./utils/message');
  const {isRealString} = require('./utils/validation');
  const {Users} = require('./utils/users');
  const publicPath = path.join(__dirname, '../public');
  const port = process.env.PORT || 3000;
  let users = new Users();
  let app = express();
  let server = http.createServer(app);
  let io = socketio(server);
  app.use(express.static(publicPath));
  
  io.on('connection', (socket) => {
      console.log('New user connected!');
  
      socket.on('join',(params,callback) => {
          if(!isRealString(params.name) || !isRealString(params.room)){
              return callback('Name and room name required');
          }
  
          socket.join(params.room);
          users.removeUser(socket.id);
          users.addUser(socket.id,params.name,params.room);
          io.to(params.room).emit('updateUserList',users.getUserList(params.room));
  
          socket.emit('newMessage',generateMessage('Admin','Welcome to the chat App'));
          socket.broadcast.to(params.room).emit('newMessage',generateMessage('Admin',`${params.name} has joined`));    
          callback();
      });
  
      socket.on('createMessage',(message,callback) => {
          let user = users.getUser(socket.id);   
          if (user && isRealString(message.text)) {
              io.to(user.room).emit('newMessage',generateMessage(user.name,message.text));
          }
          callback('Ths is from the server!');
      });
  
      socket.on('createLocationMessage',(coords) => {
          let user = users.getUser(socket.id);
          if (user) {
              io.to(user.room).emit('newLocationMessage',generateLocationMessage(user.name,coords.latitude,coords.longitude))
          }
      });
  
      socket.on('disconnect', () => {
          let user = users.removeUser(socket.id);
          io.to(user.room).emit('updateUserList',users.getUserList(user.room));
          io.to(user.room).emit('newMessage',generateMessage('Admin',`${user.name} has left`));
      });
  });
  
  server.listen(port, () => {
      console.log(`Server is up on port ${port}`);
  });