0

I'm actually working on microservices project using a nats-streaming-server as a event-bus and i trying to write a publisher.ts file but i face this erreur

PS: i'm writing this code with typescript

Property 'on' does not exist on type 'Stan'.ts(2339)

   import nats, { connect, Message } from 'node-nats-streaming';

   console.clear();


   const stan = nats.connect('ticketing', '123', {
      url: 'http://localhost:4222'
   });

   stan.on('connect', () => {
       console.log('Listener connected to NATS');

       const subscription = stan.subscribe('ticket:created');

       subscription.on('message', (msg: Message) => {
            const data = msg.getData();
            if (typeof data === 'string') {
                console.log(`Recieved event #${msg.getSequence()}, with data: ${data}`);
            }

       });
   })

1 Answers1

0

Seems like typescript doesn't know what events are. Try adding @types/events to the dependencies via npm i @types/events