Hey Stack Overflow geeks, I'm working on a real-time chat application using HTML, CSS, and js using socket.io. There I've been created an index.js file that stores the user information and strikes back the same and the other one named client.js which takes the name of the user using prompt. Both of the files has been given below
index.js
const io = require('socket.io')(5000)
const users = {};
io.on('connection', socket =>{
socket.on('new-user-joined', user =>{
console.log("New user", user)
users[socket.id] = user;
socket.broadcast.emit('user-joined', user);
});
socket.on('send', message=>{
socket.broadcast.emit('receive', {message: message, name: users[socket.id]})
});
})
client.js
const socket = io('https://localhost:5000');
const form = document.getElementById('send-container');
const messageIn = document.getElementById('messageIn');
const messageContainer = document.querySelector('.container');
const user = prompt("Enter your username")
socket.emit('new-user-joined', user);
Now the problem is that the client.js file didn't fire up the prompt for taking user input. Since I'm currently in the learning phase of web development I tried my best to know where am I getting wrong but didn't find the appropriate solution. Please help me to get to know where am I going wrong.