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

133
Vistas
Calling an event from socket.io

I'm trying to call an event, but an error occurs: UnhandledPromiseRejectionWar ning: TypeError: Cannot read property 'emit' of undefined How it is possible to bypass it? nodejs

import { io } from 'socket.io-client';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';

import { SynchronizeService } from './synchronize.service';
import { UserService } from '../user/user.service';

const serverAddress = 'http://localhost:3050'
const socket = io(serverAddress, { reconnection: true })

export class SocketClient {
constructor(
private readonly synchronizeService: SynchronizeService,
private eventEmitter: EventEmitter2,
private readonly userService: UserService
) {}

@OnEvent('order.created')
async handler(req):Promise<void> {
 try{
   socket.on('synchronize', () => {
   });
   socket.on('send_from_server', async ({ msg }) => {
     await this.eventEmitter.emitAsync('order.came')
   });
  socket.emit('synchronize', req);
} catch (e) {
  console.log(e);
}
}

}
about 4 years ago · Juan Pablo Isaza
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