Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!