Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
socket.io console.log(userName) not showing in the command line

I'm creating a chat application using socket.io, so basically what I'm trying is to console.log the user who joined the chat, here I'm taking a prompt from the client and emitting to the server, but cannot find any log in my command line. And on top I'm getting this error ERR_NAME_NOT_RESOLVED.

ERR_NAME_NOT_RESOLVED img Index Html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>See-me</title>
        <script src="http://localhost:3000/socket.io/socket.io.js"></script>
        <script src="js/client.js"></script>
        <link rel="stylesheet" href="css/styles.css">
        <link rel = "icon" href ="logo/appIcon.ico" type = "image/x-icon">
</head>
<body>
   
</body>
</html>

Client Side Js:

    const socket = io('http//localhost:3000')

    const form = document.getElementById('send-container')
    const messageInput = document.getElementById('messageImp')
    const messageContainer = document.querySelector(".container")

const userName = prompt("Enter your Name to join");
socket.emit('new-user-joined', userName)

Server Side JS:

const io = require('socket.io')(3000)

const users = {};

io.on('connection', (socket) => {
    socket.on('new-user-joined', userName =>{
        console.log("New user", userName);
        users[socket.id] = userName;
        socket.broadcast.emit('user-joined', userName)
    });

    socket.on('send', message => {
        socket.broadcast.emit('receive', {message: message, userName: users[socket.id]})
    });
})

All I want is to console log the user who joined the chat.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The error is actually pointing to what the issue is:

const socket = io('http//localhost:3000')

That URL is missing a colon after http

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda