node-notifier
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Node-notifier is a powerful tool that allows you to send cross-platform native notifications using Node.js. It utilizes Notification Center for macOS, notify-osd
/libnotify-bin
for Linux, Toasters for Windows 8/10, or taskbar balloons for prior Windows versions. If none of these systems are met, it employs Growl as a fallback option. This is the perfect solution for generating native notifications on Mac, Windows, and Linux from within your Node.js applications.
To use the node-notifier in your project, you would first need to install it via npm by running npm install --save node-notifier
. After successful installation, you can import the package into your script with const notifier = require('node-notifier')
. You can then use it to send notifications. Here's a basic example:
const notifier = require('node-notifier');
notifier.notify('Hello, world!');
You can also pass an object with title
and message
properties to the notify
method:
notifier.notify({
title: 'My notification',
message: 'Hello, there!'
});
In more advanced scenarios, you may want to have the notifier wait until a user action is taken against the notification. Below is an example of how to implement this:
notifier.notify(
{
title: 'My awesome title',
message: 'Hello from node, Mr. User!',
wait: true
},
function (err, response) {
// Response is response from notification
}
);
notifier.on('click', function (notifierObject, options) {
// Triggers if `wait: true` and user clicks notification
});
notifier.on('timeout', function (notifierObject, options) {
// Triggers if `wait: true` and notification closes
});
The comprehensive documentation for node-notifier can be found within the project's repository on GitHub. You can locate valuable resources on specific aspects such as how to use alerts for the Notification Center, Windows Toaster, Windows Balloon, Growl, and Notify-send. Each section provides insights into the functionality, requirements, and offer usage examples. To get started, visit the GitHub page for node-notifier and scroll down to the documentation sections.