I'm using node to make an email client. I want to update the browser window as soon as any new email arrives. I'm already fetching the emails on server side using mail-listener2. I want to push that data to client side. How do i do that?
Methods to send response from server to client are:Using send() function. Using json() function.
In order to set up web push, you need to create a set of VAPID keys. VAPID keys identify who is sending the push notification. The web-push npm module can generate VAPID keys for you, so let's install web-push along with some other dependencies and use web-push generate-vapid-keys to create the keys.
Other reasons why we cannot use node modules at the client side is that the node uses the CommonJS module system while the browser uses standard ES Modules which has different syntax.
Look at using websockets to push data in realtime to the client (browser). I would recommend using http://socket.io. They have some really great demos on there to show how you would do something like this.
Your server would send socket.io messages called message
, containing the message details as JSON. Your client would listen for message
events and update the UI as they come in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With