1

I am using Angular CLI latest version and NodeJS, want to archive web push notification, we got few documentations but gives error, May I know any Documentation for web push notification which supports angular and nodejs.

The requirements are send push notification to all users who notification granted while browser closed as well.

Sample docs :

  1. https://ciphertrick.com/2017/03/14/browser-push-notifications-in-angular-applications/ (getting error pushNotificationModule not exported)
  2. https://www.npmjs.com/package/angular2-notifications (Not clear for CLI)
151291
  • 3,308
  • 7
  • 48
  • 81
  • Did you find a solution? I have the same question. Please shared your knowledge to help me and others. You can answer your own question and people can give you credit for that. – Herman Fransen Jan 11 '18 at 09:12
  • @HermanFransen - not yet will share you once success, I am trying to use older version of angular cli. you also try once and let me know. – 151291 Jan 11 '18 at 12:21

1 Answers1

0

The Angular2+ directive angular2-notifications is doing only the last part showing the message in UI/UX. And that is the least of your challenges.

You say:

The requirements are send push notification to all users who notification granted while browser closed as well

The part 'while browser closed as well' is the tricky part.

This means 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 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.

I don't think setting up a WebSocket connection (like socket.io) from Node to a Service Worker is possible. It's complicated, some people say it's possible, others say no. See this for more info. I would at least say that it is not stable enough, so you need a 'real' push notification.

You can use a push notification provider to do the job. Click here for a list of them. You pay for these services.

If you want to do it yourself (free of costs) you can use Google's cross-platform messaging solution Firebase Cloud Messaging (FCM) (the successor of Google Cloud Messaging (GCM)).

To connect your NodeJS server with the FCM you can use different libraries e.g. node-pushserver and many others.

Herman Fransen
  • 2,200
  • 5
  • 24
  • 40