DEV Community

Cover image for Send Notifications Through Node.js App! πŸ”₯
Sujeet Gund
Sujeet Gund

Posted on • Updated on

Send Notifications Through Node.js App! πŸ”₯

In this article, we are going to learn how we can create notifications/reminder in Windows/ MacOS with your Node.js app.

Sample Shots 1

Approach:

To make a notification through our node app, we are going to use node-notifier package. It is already a quiet popular package with more than 9M weekly downloads!

About this package:
Package Size Package Downloads

Steps:

  1. Do the initial setup for node app.

  2. Install the package:

yarn add node-notifier
Enter fullscreen mode Exit fullscreen mode

or

npm install node-notifier
Enter fullscreen mode Exit fullscreen mode
  1. Quickstart with this short code: add this code in your index.js
const notifier = require('node-notifier');


// Object
notifier.notify({
  title: 'My notification',
  message: 'Hello, there!'
});
Enter fullscreen mode Exit fullscreen mode

You can further add more custom option in it like icon, wait for user action, timeout, reply etc.

const notifier = require('node-notifier');
const path = require('path');

notifier.notify(
  {
    title: 'My awesome title',
    message: 'Hello from node, Mr. User!',
    icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
    sound: true, // Only Notification Center or Windows Toasters
    wait: true // Wait with callback, until user action is taken against notification, does not apply to Windows Toasters as they always wait or notify-send as it does not support the wait option
  },
  function (err, response, metadata) {
    // Response is response from notification
    // Metadata contains activationType, activationAt, deliveredAt
  }
);

notifier.on('click', function (notifierObject, options, event) {
  // Triggers if `wait: true` and user clicks notification
});

notifier.on('timeout', function (notifierObject, options) {
  // Triggers if `wait: true` and notification closes
});
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Note: This package has its own system requirements.

  • macOS: >= 10.8 for native notifications. _
  • Linux: _notify-osd or libnotify-bin installed (Ubuntu should have this by default) _
  • Windows: >= 8, or task bar balloons for Windows < 8.
  • And if not met any requirement then it will use Growl.

More know about this package on:


Hit like if you found this article interested and feel free to ask queries!


Also read:

How to send SMS with Nodejs App
Awesome VS Code Customizations

Discussion (0)