Node Notifier CLI
node-notifier-cli is a command-line interface (CLI) package that provides a convenient way to send cross-platform desktop notifications. It acts as a wrapper around the `node-notifier` library, enabling users to trigger notifications directly from their terminal or shell scripts without writing JavaScript code. It supports various notification systems including macOS Notification Center (since 10.8), Windows Toast notifications, Growl, and `notify-send` for Linux. Version 2.0.0 is the current stable release, with its last major update occurring approximately five years ago. Its release cadence is closely tied to its underlying `node-notifier` library, which provides the core notification functionality. The package differentiates itself from programmatic notification libraries by offering a simple, unified command-line syntax for sending messages, titles, icons, and even opening URLs on click, focusing solely on CLI usability.
Common errors
-
notify: command not found
cause The `node-notifier-cli` package, and thus the `notify` executable, is not installed globally or is not in your system's PATH.fixInstall the package globally: `npm i -g node-notifier-cli` or ensure that the local `node_modules/.bin` directory is in your PATH if installed locally. -
Notifications not appearing on Linux (Ubuntu/Debian-like systems)
cause The required system utility, `notify-send` (provided by `libnotify-bin`), is not installed.fixInstall `libnotify-bin`: `sudo apt-get install libnotify-bin`. -
Notifications not appearing in Windows Subsystem for Linux (WSL2)
cause WSL2 environment may not have proper display server integration or permissions to forward notifications to the Windows host OS.fixEnsure your WSL2 setup is configured for GUI applications, potentially involving an X server, or modify Windows permissions for the `SnoreToast.exe` binary used by `node-notifier`. Refer to `node-notifier`'s documentation on 'Windows and WSL2' for detailed steps. -
Notification timeout behavior is inconsistent on Windows, often disappearing quickly.
cause On Windows, the `wait` and `timeout` options for toast notifications can be inconsistent. The system often enforces a default display duration (e.g., 5 seconds) regardless of settings, and 'sticky' notifications are not universally supported.fixBe aware that custom `timeout` settings may not always be honored on Windows for transient toast notifications. For longer-lasting notifications, consider using the `actions` or `reply` options which inherently require a user interaction to dismiss, or explore platform-specific sticky notification solutions outside of this CLI.
Warnings
- breaking The underlying `node-notifier` library, which `node-notifier-cli` depends on, had a Command Injection vulnerability (CVE-2020-28283) in versions less than 5.4.5, and specifically in the range `>=8.0.0 <8.0.2`, and `>=9.0.0 <9.0.1`. `node-notifier-cli@2.0.0` depends on `node-notifier@^8.0.1`, which is within the vulnerable range. This means `node-notifier-cli@2.0.0` is directly susceptible to arbitrary command execution on Linux systems if user-provided input (e.g., from `--title`, `--message`, `--icon`) is not properly sanitized before being passed to the CLI.
- breaking The CLI functionality was removed from the main `node-notifier` package starting with version `5.0.0` and moved into this separate `node-notifier-cli` package. Users updating `node-notifier` to `5.0.0` or higher would lose the `notify` command if they did not also install `node-notifier-cli`.
- gotcha On macOS, custom icons specified with the `--icon` option may not display as the primary notification icon. macOS notifications often display the icon of the parent application initiating the notification (which is `terminal-notifier` in this case). To use a truly custom icon, one generally needs to fork and recompile `terminal-notifier` with the desired icon embedded.
- gotcha The `--subtitle` option is explicitly noted as 'not available on Windows OS'. Attempting to use this option on Windows will have no effect. [cite: README]
- gotcha `node-notifier` (and by extension `node-notifier-cli`) relies on native OS tools for notifications. For Linux, `notify-osd` or `libnotify-bin` must be installed. For macOS, `terminal-notifier` is used (which is bundled). Without these, notifications may fail or fall back to less preferred methods (like Growl).
- gotcha The `--sound` option on macOS supports specific system sounds (e.g., `Basso`, `Bottle`, `Glass`). Using `true` as a value will default to 'Bottle'. Using an invalid sound name or `true` on platforms that don't support it (e.g., Windows Toasters or `notify-send`) might result in no sound or a default system sound, not an error.
Install
-
npm install node-notifier-cli -
yarn add node-notifier-cli -
pnpm add node-notifier-cli
Imports
- notify
import { notify } from 'node-notifier-cli'notify -t 'Task Complete' -m 'Your build finished successfully!'
- npx
npx notify -m 'Message'
npx -p node-notifier-cli notify -t 'Reminder' -m 'Don\'t forget that meeting at 3 PM!' -s Glass
- spawn
spawn('node-notifier-cli', ['-t', 'Title', '-m', 'Message'])import { spawn } from 'child_process'; const title = 'System Alert'; const message = 'Disk space low! Cleanup recommended.'; const icon = 'https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/coulson.jpg'; const child = spawn('notify', ['-t', title, '-m', message, '--icon', icon, '-s', 'Basso']); child.on('error', (err) => { console.error('Failed to start notify process:', err.message); }); child.on('close', (code) => { if (code !== 0) { console.warn(`notify process exited with code ${code}`); } });
Quickstart
# Install globally (recommended for CLI usage) npm i -g node-notifier-cli # Basic notification notify -t 'Hello World' -m 'This is a test notification from the CLI.' # Notification with sound and opening a URL on click notify -t 'GitHub Update' -m 'New pull request on your repository!' -s Basso --open 'https://github.com/mikaelbr/node-notifier-cli' # Notification with a custom icon notify -t 'Agent Coulson' --icon 'https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/coulson.jpg' -m 'I know, right?' # Pipe content to message echo "This message comes from stdin!" | notify -t "Piped Message"