Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Notifications RESTful WebApp Angular2 / NodeJS

I'm working on a Restful Web Application. I divide frontend and backend, using Angular2 for the front, and NodeJS for the back.

I would like to use Notifications and push them to specific users.

Sample : If my user decide to subscribe, he could get a Desktop notification when I decide to send one or if my NodeJS serveur want to send a message to a user group.

I have seen a lot of differents modules for the frontend and backend, but I'm a little bit lost.

Architecturally, how should I add this service in my application? Should I use specific node modules?

like image 493
Lewis Godgiven Avatar asked Dec 16 '25 13:12

Lewis Godgiven


1 Answers

You talk about desktop notifications. I guess you want the user to receive its notifications also when the browser or app is closed. In that case you need a Service Worker. A Service Worker is a script that your browser runs in the background, to which the message is being pushed when the browser or app is closed. For a nice introduction to Service Workers, read this. Angular has a Service Workers implemented in production version since 5.0.0. Klik here to read more about it.

At the backend you need a special Node module to send the notification. For instance node-pushserver, but there are many others. This special node module connects to a messaging service whom actual send the message. You can use for instance Google's cross-platform messaging solution Firebase Cloud Messaging (FCM) (the successor of Google Cloud Messaging (GCM)). It can send to Web, iOS and Android.

At the client side you need to register the Service Worker for push notification. Then you will get an endpoint that needs to be stored at the node server side. You send a push request with this endpoint to the messaging service every time.

You can also make use of a paid push notification provider to do the job. Click here for a list of them.

Setting up a WebSocket connection (like socket.io) won't work since it can't stay connected with the Service Worker.

like image 140
Herman Fransen Avatar answered Dec 19 '25 05:12

Herman Fransen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!