For more control, use an options object with notifier.notify(). You can provide a title, message, icon path, sound toggle, and a wait flag.
When wait: true is used, the callback function is executed when the user interacts with the notification. Note that wait does not apply to Windows Toasters or notify-send (Linux).
Available events:
click: Triggers if wait: true and the user clicks the notification.timeout: Triggers if wait: true and the notification closes automatically.
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
},
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
});