Send Notifications Through Node.js App! 🔥
Sujeet Gund
Posted on June 28, 2022
In this article, we are going to learn how we can create notifications/reminder in Windows/ MacOS with your Node.js app.
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!
Steps:
Do the initial setup for node app.
Install the package:
yarn add node-notifier
or
npm install node-notifier
- 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!'
});
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
});
💡 Note: This package has its own system requirements.
- macOS: >= 10.8 for native notifications. _
- Linux: _
notify-osd
orlibnotify-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
Posted on June 28, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.