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
Why does exporting the socket.io server as a constant using module.exports? make it undefined?

I am runnnig a socketserver in express but I am unable to export the io constant to a different file without it becoming undefined. I, therefore, cannot use io.on( ), it gives a type error. When i tried to console.log it, its undefined. Please help

server.js:

const app = require("express")();
const httpServer = require("http").createServer(app);
const io = require("socket.io")(httpServer, options);
// const io = new Server(server, options)
io.on("connection", socket => { console.log('hello') });

...

module.exports = {httpServer, app, io};

router.js:

const  {io}  = require("../server.js");
// console.log(io)
over 4 years ago · Santiago Trujillo
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