In some cases, you may already have an existing Express app and you want to mount an EventSub listener into it.
This is made easy with the EventSubMiddleware class.
You just need to follow some easy steps to make sure the events come through:
.apply(app)
method, passing your Express app as parameter.markAsReady()
methodNow you can continue subscribing to your desired EventSub events as usual.
const middleware = new EventSubMiddleware({
apiClient,
hostName: 'example.com',
pathPrefix: '/twitch',
secret: 'secretHere'
});
middleware.apply(app);
app.listen(3000, async () => {
await middleware.markAsReady();
middleware.onChannelFollow('125328655', event => {
console.log(`${event.userDisplayName} just followed ${event.broadcasterDisplayName}!`);
});
});