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

256
Vistas
NodeJs - Socket.io, Can't access socket.io.js trough js file

I want to access socket.io.js trough an external js file (in my case called script.js), but I am getting the following error when trying to access trough the client side js file.

Uncaught ReferenceError: io is not defined

But when using js inside of my html it works fine. My Node.js API serves socket.io.js correctly and is accessable. Following html code works without errors.

<script src="/socket.io/socket.io.js"></script>
    <script>
        const socket = io();
        socket.on('message', function (message) {
        console.log(message);
        });

    </script>
</script>

While external js code doesn't work

const socket = io();
socket.on('message', function (message) {
console.log(message);
});

All js file are linked in head of my html

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

0

I'm kinda dump found my mistake called my script.js in header before socket.io.js

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