• Stars
    star
    5,711
  • Rank 6,839 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Node.js module for sending notifications on native Mac, Windows and Linux (or Growl as fallback)

node-notifier NPM version Install size Build Status

Send cross platform native notifications using Node.js. Notification Center for macOS, notify-osd/libnotify-bin for Linux, Toasters for Windows 8/10, or taskbar balloons for earlier Windows versions. Growl is used if none of these requirements are met. Works well with Electron.

macOS Screenshot Native Windows Screenshot

Input Example macOS Notification Center

Input Example

Actions Example Windows SnoreToast

Actions Example

Quick Usage

Show a native notification on macOS, Windows, Linux:

const notifier = require('node-notifier');
// String
notifier.notify('Message');

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

Requirements

  • macOS: >= 10.8 for native notifications, or Growl if earlier.
  • Linux: notify-osd or libnotify-bin installed (Ubuntu should have this by default)
  • Windows: >= 8, or task bar balloons for Windows < 8. Growl as fallback. Growl takes precedence over Windows balloons.
  • General Fallback: Growl

See documentation and flow chart for reporter choice.

Install

npm install --save node-notifier

CLI

CLI has moved to separate project: https://github.com/mikaelbr/node-notifier-cli

Cross-Platform Advanced Usage

Standard usage, with cross-platform fallbacks as defined in the reporter flow chart. All of the options below will work in some way or another on most platforms.

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
});

If you want super fine-grained control, you can customize each reporter individually, allowing you to tune specific options for different systems.

See below for documentation on each reporter.

Example:

const NotificationCenter = require('node-notifier/notifiers/notificationcenter');
new NotificationCenter(options).notify();

const NotifySend = require('node-notifier/notifiers/notifysend');
new NotifySend(options).notify();

const WindowsToaster = require('node-notifier/notifiers/toaster');
new WindowsToaster(options).notify();

const Growl = require('node-notifier/notifiers/growl');
new Growl(options).notify();

const WindowsBalloon = require('node-notifier/notifiers/balloon');
new WindowsBalloon(options).notify();

Or, if you are using several reporters (or you're lazy):

// NOTE: Technically, this takes longer to require
const nn = require('node-notifier');

new nn.NotificationCenter(options).notify();
new nn.NotifySend(options).notify();
new nn.WindowsToaster(options).notify(options);
new nn.WindowsBalloon(options).notify(options);
new nn.Growl(options).notify(options);

Contents

Usage: NotificationCenter

Same usage and parameter setup as terminal-notifier.

Native Notification Center requires macOS version 10.8 or higher. If you have an earlier version, Growl will be the fallback. If Growl isn't installed, an error will be returned in the callback.

Example

Because node-notifier wraps around terminal-notifier, you can do anything terminal-notifier can, just by passing properties to the notify method.

For example:

  • if terminal-notifier says -message, you can do {message: 'Foo'}
  • if terminal-notifier says -list ALL, you can do {list: 'ALL'}.

Notification is the primary focus of this module, so listing and activating do work, but they aren't documented.

All notification options with their defaults:

const NotificationCenter = require('node-notifier').NotificationCenter;

var notifier = new NotificationCenter({
  withFallback: false, // Use Growl Fallback if <= 10.8
  customPath: undefined // Relative/Absolute path to binary if you want to use your own fork of terminal-notifier
});

notifier.notify(
  {
    title: undefined,
    subtitle: undefined,
    message: undefined,
    sound: false, // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below)
    icon: 'Terminal Icon', // Absolute Path to Triggering Icon
    contentImage: undefined, // Absolute Path to Attached Image (Content Image)
    open: undefined, // URL to open on Click
    wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds

    // New in latest version. See `example/macInput.js` for usage
    timeout: 5, // Takes precedence over wait if both are defined.
    closeLabel: undefined, // String. Label for cancel button
    actions: undefined, // String | Array<String>. Action label or list of labels in case of dropdown
    dropdownLabel: undefined, // String. Label to be used if multiple actions
    reply: false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
  },
  function (error, response, metadata) {
    console.log(response, metadata);
  }
);

Note: The wait option is shorthand for timeout: 5. This just sets a timeout for 5 seconds. It does not make the notification sticky!

As of Version 6.0 there is a default timeout set of 10 to ensure that the application closes properly. In order to remove the timeout and have an instantly closing notification (does not support actions), set timeout to false. If you are using action it is recommended to set timeout to a high value to ensure the user has time to respond.

Exception: If reply is defined, it's recommended to set timeout to a either high value, or to nothing at all.


For macOS notifications: icon, contentImage, and all forms of reply/actions require macOS 10.9.

Sound can be one of these: Basso, Blow, Bottle, Frog, Funk, Glass, Hero, Morse, Ping, Pop, Purr, Sosumi, Submarine, Tink.

If sound is simply true, Bottle is used.


See Also:


Custom Path clarification

customPath takes a value of a relative or absolute path to the binary of your fork/custom version of terminal-notifier.

Example: ./vendor/mac.noindex/terminal-notifier.app/Contents/MacOS/terminal-notifier

Spotlight clarification

terminal-notifier.app resides in a mac.noindex folder to prevent Spotlight from indexing the app.

Usage: WindowsToaster

Note: There are some limitations for images in native Windows 8 notifications:

  • The image must be a PNG image
  • The image must be smaller than 1024ร—1024ย px
  • The image must be less than 200kb
  • The image must be specified using an absolute path

These limitations are due to the Toast notification system. A good tip is to use something like path.join or path.delimiter to keep your paths cross-platform.

From mikaelbr/gulp-notify#90 (comment)

You can make it work by going to System > Notifications & Actions. The 'toast' app needs to have Banners enabled. (You can activate banners by clicking on the 'toast' app and setting the 'Show notification banners' to On)


Windows 10 Fall Creators Update (Version 1709) Note:

Snoretoast is used to get native Windows Toasts!

The default behaviour is to have the underlying toaster applicaton as appID. This works as expected, but shows SnoreToast as text in the notification.

With the Fall Creators Update, Notifications on Windows 10 will only work as expected if a valid appID is specified. Your appID must be exactly the same value that was registered during the installation of your app.

You can find the ID of your App by searching the registry for the appID you specified at installation of your app. For example: If you use the squirrel framework, your appID will be something like com.squirrel.your.app.

const WindowsToaster = require('node-notifier').WindowsToaster;

var notifier = new WindowsToaster({
  withFallback: false, // Fallback to Growl or Balloons?
  customPath: undefined // Relative/Absolute path if you want to use your fork of SnoreToast.exe
});

notifier.notify(
  {
    title: undefined, // String. Required
    message: undefined, // String. Required if remove is not defined
    icon: undefined, // String. Absolute path to Icon
    sound: false, // Bool | String (as defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx)
    id: undefined, // Number. ID to use for closing notification.
    appID: undefined, // String. App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible.
    remove: undefined, // Number. Refer to previously created notification to close.
    install: undefined // String (path, application, app id).  Creates a shortcut <path> in the start menu which point to the executable <application>, appID used for the notifications.
  },
  function (error, response) {
    console.log(response);
  }
);

Usage: Growl

const Growl = require('node-notifier').Growl;

var notifier = new Growl({
  name: 'Growl Name Used', // Defaults as 'Node'
  host: 'localhost',
  port: 23053
});

notifier.notify({
  title: 'Foo',
  message: 'Hello World',
  icon: fs.readFileSync(__dirname + '/coulson.jpg'),
  wait: false, // Wait for User Action against Notification

  // and other growl options like sticky etc.
  sticky: false,
  label: undefined,
  priority: undefined
});

See more information about using growly.

Usage: WindowsBalloon

For earlier versions of Windows, taskbar balloons are used (unless fallback is activated and Growl is running). The balloons notifier uses a great project called notifu.

const WindowsBalloon = require('node-notifier').WindowsBalloon;

var notifier = new WindowsBalloon({
  withFallback: false, // Try Windows Toast and Growl first?
  customPath: undefined // Relative/Absolute path if you want to use your fork of notifu
});

notifier.notify(
  {
    title: undefined,
    message: undefined,
    sound: false, // true | false.
    time: 5000, // How long to show balloon in ms
    wait: false, // Wait for User Action against Notification
    type: 'info' // The notification type : info | warn | error
  },
  function (error, response) {
    console.log(response);
  }
);

See full usage on the project homepage: notifu.

Usage: NotifySend

Note: notify-send doesn't support the wait flag.

const NotifySend = require('node-notifier').NotifySend;

var notifier = new NotifySend();

notifier.notify({
  title: 'Foo',
  message: 'Hello World',
  icon: __dirname + '/coulson.jpg',

  wait: false, // Defaults no expire time set. If true expire time of 5 seconds is used
  timeout: 10, // Alias for expire-time, time etc. Time before notify-send expires. Defaults to 10 seconds.

  // .. and other notify-send flags:
  'app-name': 'node-notifier',
  urgency: undefined,
  category: undefined,
  hint: undefined
});

See flags and options on the man page notify-send(1)

Thanks to OSS

node-notifier is made possible through Open Source Software. A very special thanks to all the modules node-notifier uses.

NPM downloads

Common Issues

How to use SnoreToast with both appID and actions

See this issue by Araxeus.

Windows: SnoreToast text

See note on "Windows 10 Fall Creators Update" in Windows section. Short answer: update your appID.

Windows and WSL2

If you don't see notifications within WSL2, you might have to change permission of exe vendor files (snoreToast). See issue for more info

Use inside tmux session

When using node-notifier within a tmux session, it can cause a hang in the system. This can be solved by following the steps described in this comment

Thereโ€™s even more info here #61 (comment).

macOS: Custom icon without Terminal icon

Even if you define an icon in the configuration object for node-notifier, you will see a small Terminal icon in the notification (see the example at the top of this document).

This is the way notifications on macOS work. They always show the icon of the parent application initiating the notification. For node-notifier, terminal-notifier is the initiator, and it has the Terminal icon defined as its icon.

To define your custom icon, you need to fork terminal-notifier and build your custom version with your icon.

See Issue #71 for more info #71.

Within Electron Packaging

If packaging your Electron app as an asar, you will find node-notifier will fail to load.

Due to the way asar works, you cannot execute a binary from within an asar. As a simple solution, when packaging the app into an asar please make sure you --unpack the vendor/ folder of node-notifier, so the module still has access to the notification binaries.

You can do so with the following command:

asar pack . app.asar --unpack "./node_modules/node-notifier/vendor/**"

Or if you use electron-builder without using asar directly, append build object to your package.json as below:

...
build: {
  asarUnpack: [
    './node_modules/node-notifier/**/*',
  ]
},
...

Using with pkg

For issues using with the pkg module. Check this issue out: #220 (comment)

Using Webpack

When using node-notifier inside of webpack, you must add the snippet below to your webpack.config.js.

This is necessary because node-notifier loads the notifiers from a binary, so it needs a relative file path. When webpack compiles the modules, it suppresses file directories, causing node-notifier to error on certain platforms.

To fix this, you can configure webpack to keep the relative file directories. Do so by append the following code to your webpack.config.js:

node: {
  __filename: true,
  __dirname: true
}

License

This package is licensed using the MIT License.

SnoreToast and Notifu have licenses in their vendored versions which do not match the MIT license, LGPL-3 and BSD 3-Clause to be specific. We are not lawyers, but have made our best efforts to conform to the terms in those licenses while releasing this package using the license we chose.

More Repositories

1

awesome-es2015-proxy

For learning how to use JavaScript Proxy, or just to see what is possible
JavaScript
600
star
2

gulp-notify

gulp plugin to send messages based on Vinyl Files or Errors to Mac OS X, Linux or Windows using the node-notifier module. Fallbacks to Growl or simply logging
JavaScript
592
star
3

marked-terminal

A Renderer for the marked project. Allowing you to render Markdown to print to your Terminal
JavaScript
405
star
4

mversion

A cross packaging module version bumper. CLI or API for bumping versions of package.json, bower.json, *.jquery.json etc.
JavaScript
199
star
5

node-notifier-cli

CLI API for node-notifier as separate package.
JavaScript
142
star
6

SocialFeed.js

Generate a social feed in javascript.
JavaScript
132
star
7

metatune

PHP Wrapper for the Spotify Metadata API and the Spotify Play Button
PHP
55
star
8

node-osascript

A stream for Apple Open Scripting Architecture (OSA) through AppleScript or Javascript
JavaScript
50
star
9

bacon-love

A Nodeschool type workshop for Functional Reactive Programming and Bacon.js
JavaScript
48
star
10

fp-react

Functional tools for React components
JavaScript
41
star
11

vscodemod

VSCode extension for doing codemod on selected text
JavaScript
30
star
12

did-i-do-that

A debug tool based on JavaScript Proxy to track surprising/unwanted mutation of objects.
JavaScript
26
star
13

gulp-gitmodified

A plugin for Gulp to get an object stream of modified files on git.
JavaScript
22
star
14

frp-piano

An example of Functional Reactive Programming, by implementing a simple collaborative piano.
CSS
19
star
15

node-heartrate

A Bluethooth Low Energy heart rate stream
JavaScript
15
star
16

babel-plugin-transform-react-require

Transform files using JSX to implicitly require React (or other implementations).
JavaScript
15
star
17

gulp-gitshasuffix

A plugin for Gulp to suffix files with latest commit sha.
JavaScript
11
star
18

chrome-github-packages

Enhance Package.json on Github by linking up modules to NPM
JavaScript
11
star
19

mrun

mrun - A npm module for setting npm run properties to build/watch less and browserify code
JavaScript
10
star
20

lastfm-spotify-urilist

A Node.js module for an easy way of getting a list of Spotify URIs based on Last.fm data.
JavaScript
10
star
21

markdowner

Markdowner is a cloud based application for writing and sharing Markdown documents.
JavaScript
9
star
22

cli-usage

Easily show the usage of your CLI tool from a Markdown string or file
JavaScript
9
star
23

AI-Poker-Player

NTNU Project for AI Programming
Python
8
star
24

metabrag

A jQuery plugin for showing off your GitHub and Coderwall stats.
JavaScript
7
star
25

kodesnutt

Kode brukt i episoder av Kodesnutt.io
JavaScript
5
star
26

simplify-playbutton

Automated service for generating Spotify Play Button for your Last.fm scrobbled tracks. Using Node.js and running on Heroku.
JavaScript
5
star
27

kakle

If Commit, Then Do. Kakle helps you remember when you should run commands after pulling external changes
JavaScript
5
star
28

clapper

Do actions on applause and listen on claps on browser usermedia
JavaScript
4
star
29

node-csstats

Parse AMX Mod X Stats File. A result of procrastinating during a Master's thesis and nostalgia.
JavaScript
4
star
30

SwarmWebots

Project 4 - Artificial Swarm Behavior
Python
4
star
31

record-access

Property accessors as functions similar to .property in elm-lang.
JavaScript
4
star
32

traceur-cli

Wraps traceur cli to add REPL and string eval
JavaScript
4
star
33

didt

Did I do that?
JavaScript
3
star
34

bacon.decorate

Unify your API and abstract time using Functional Reactive Programming and Bacon.js
JavaScript
3
star
35

json-ast

OCaml JSON AST generator. Work in progress
OCaml
3
star
36

phpcoderwall

PHP library for fetching Coderwall data
PHP
3
star
37

presentations

A collection of presentations
JavaScript
3
star
38

graphql-node-import

Import `.graphql` and `.gql` files directly in Node, accessing queries and fragments
TypeScript
3
star
39

nextjs-css-relative-assets-bug-repro

JavaScript
2
star
40

standalone-unrar

A standalone unrar library without any need for external dependencies.
JavaScript
2
star
41

diy-nextjs-server-actions

Example code from presentation "DIY Nextjs Server Actions"
TypeScript
2
star
42

node-repo-github

A very simple node.js wrapper to get Github Repo Information.
JavaScript
2
star
43

twit-stream

Streaming Twitter data with proper Node.JS streams2 with a simple API
JavaScript
2
star
44

rm-debugger

Simplest codemod you can think of, but is still handy: Remove all `debugger;` statements from your code.
JavaScript
2
star
45

react-formdata

A library for generating an object of values from a set of inputs in React
JavaScript
2
star
46

mikaelbr

My special repository
2
star
47

twitscraper

A binary used for scraping the Twitter site for tweets and generate a .tsv file for output
JavaScript
2
star
48

release-actions-demo

JavaScript
1
star
49

bekk-open-source

Repo brukt for planlegging av faggruppearbeid ifm. Open Source
1
star
50

Basic-Evolutionary-Programming

The code for a University project
Python
1
star
51

metaenter

A simple jQuery plugin for simulating a facebook-like text input.
JavaScript
1
star
52

dotfiles

My dotfiles used for importing to new systems and backup
Shell
1
star
53

simplserv

A simple HTTP server using Python. For web development and testing AJAX calls.
Python
1
star
54

aoc22

Advent of Code solutions for 2022 in OCaml
OCaml
1
star
55

lsystem-reasonml

ReasonML experimentation implementing Lindenmayer system
OCaml
1
star
56

AnnWebots

Project 3 - Webots with Generic Anns
Python
1
star
57

stringywingy

Check if a sentence or a word is an anagram or a palindrome.
JavaScript
1
star
58

kodesnutt.io

Kodesnutt.io homepage
HTML
1
star
59

tweetsa

Python
1
star
60

bekk-trhfrontend-prosjektoppsett

Oppsett av nye frontendprosjekter med transpilering og LESS. Stegvis guide til hvordan det kan gjรธres.
JavaScript
1
star
61

podcast-player

CLI tool for listening to podcasts.
JavaScript
1
star
62

webkom-kurs2015

Kurs for Webkom Kickoff 2015.
JavaScript
1
star
63

tdcinfographic-raspberry

Server component to the tdcinfographic application. Connecting to the tdcinfographic Node.js app through WebSockets.
Python
1
star
64

asyncjs.kodesnutt.io-source

Source for asyncjs.kodesnutt.io
CSS
1
star
65

async-kodesnutt

CSS
1
star
66

simplify-zones

Simplify geometry of tariff zones from Entur
JavaScript
1
star
67

webkom-kurs2015-webpack

Kurs for Webkom Kickoff 2015 - WebPack versjon
JavaScript
1
star
68

gifme

gifme client for posting gifs to Slack
OCaml
1
star
69

ndc

My talk for NDC2014: Functional Reactive Programming and Bacon
JavaScript
1
star
70

tweetannotator

A web tool for annotating sentiment on random tweets. Can be used to generate data sets for machine learning algorithms
JavaScript
1
star
71

CP-Sudoku

Constraint based sudoku solver
Java
1
star
72

immutable-memo

Memoization with immutable data structures for React.memo
JavaScript
1
star
73

textareaAutoHeight

Create a Facebook like input box in seconds. A text area will automaticly set height according to content, and submit on enter, but give new line at shift + enter.
JavaScript
1
star
74

auto-unrar

Automatic unpack all recursive rar-files from a directory
JavaScript
1
star
75

azure-ml-text-analysis

API Wrapper for doing text analysis on Azure Machine Learning Platform
JavaScript
1
star
76

cheerful.dev

Test site for Svelte, Sapper and Now.sh
Svelte
1
star
77

Coding-Dojo-Counter

A web application for selecting sparrers and keeping time in Coding Dojos. Integration with Facebook Events
JavaScript
1
star