DEV Community

Cover image for Pusher to get Real Time Updates For Your WebApp.
Mukund Raghav Sharma (Moko)
Mukund Raghav Sharma (Moko)

Posted on

Pusher to get Real Time Updates For Your WebApp.

Introduction

I recently discovered Pusher that provides real time communication amongst different processes whether it be server to server or server to client.

I followed this tutorial for a MERN stack based messaging app I am currently working on. With just a few lines of code after setting up the Pusher project, I was able to receive updates of my MongoDb instance on my frontend.

Basics

Pusher allows you to send and receive events from channels.

Server Side

From the server side, you trigger events based on the event names on a particular channel such as the following:

The library to be used on the server can be installed by the following command:

npm i pusher
Enter fullscreen mode Exit fullscreen mode

Client Side

The client side, you subscribe to particular channels and bind to events both based on the respective names such as the following useEffect:

The library to be used on the client side can be installed by the following command:

npm i pusher-js
Enter fullscreen mode Exit fullscreen mode

Conclusion

To summarize in the context of MERN apps, in your server, you observe changes to your data from MongoDB and send those updates on particular channels and with specific event names. And on your front end, you subscribe to the channel and bind to the event names for your real time updates.

The setup was smooth and the free tier benefits are definitely generous with great documentation.

I'd be interested to hear about your experience with other similar technologies or any other information about Pusher.

Top comments (1)

Collapse
 
codesushil profile image
Code With Sushil

Good