{"id":28076765,"url":"https://github.com/jaredhanson/node-notifications","last_synced_at":"2025-07-17T20:34:20.973Z","repository":{"id":1516114,"uuid":"1774302","full_name":"jaredhanson/node-notifications","owner":"jaredhanson","description":"A mechanism for dispatching notifications within a Node.js program.","archived":false,"fork":false,"pushed_at":"2012-08-15T17:48:21.000Z","size":128,"stargazers_count":22,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T23:54:35.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-05-20T01:07:46.000Z","updated_at":"2020-11-17T07:32:58.000Z","dependencies_parsed_at":"2022-08-16T13:35:08.187Z","dependency_job_id":null,"html_url":"https://github.com/jaredhanson/node-notifications","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fnode-notifications","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fnode-notifications/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fnode-notifications/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fnode-notifications/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/node-notifications/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856616,"owners_count":21974576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-13T01:50:17.883Z","updated_at":"2025-05-13T01:50:18.475Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notifications\n\nNotifications provides an architecture for broadcasting notifications within a\n[Node.js](http://nodejs.org/) application.\n\nNotifications builds on Node's powerful concepts of [events](http://nodejs.org/docs/v0.6.4/api/events.html),\nand introduces an more decoupled approach.  In order to receive events from an\nobject, the listener must first obtain a reference to the emitting object in\norder to register as a listener.  This coupling of two objects can be\nundesirable, especially when when it would join two otherwise independent\nsubsystems.\n\nFor these scenarios, a broadcast mechanism is introduced in which objects post\nnotifications to a notification center, which dispatches them to any registered\nobservers.\n\n## Installation\n\n    $ npm install notifications\n\n## Usage\n\n#### Register an Observer\n\nRegister an observer function with the notification center.  Whenever a\nnotification with the given `name` is posted, the function will be called.\nThe `notif` passed as an argument to the function has `object` and `info`\nproperties which contain related information.\n\n    notifications.on('users.new', function(notif) {\n      var user = notif.object;\n      if (notif.info.lang == 'en') {\n        email.send({ to: user.email }, 'Welcome ' + user.firstName + '!');\n      } else {\n        // localize emails!\n      }\n    });\n\n#### Post a Notification\n\nWhen an interesting event occurs in the application, post a notification to the\nnotification center.  In this example, a notification is posted whenever a new\nuser account is created.  Observers implement necessary post-processing logic,\nsuch as sending welcome emails, and are fully decoupled.  The web application\nand email delivery subsystems remain discreet components.\n\n    app.post('/users', function(req, res) {\n      // create a new user record in database\n      var user = new User(...);\n      user.save(function(err) {\n        // user record saved, post a notification\n        // observers will be notified, triggering welcome email, etc.\n        notifications.post('users.new', user, { language: 'en' });\n        res.redirect('/');\n      });\n    });\n    \n#### NotificationCenter Instances\n\nA default `NotificationCenter` is the main export of the notifications module.\nThis instance is shared within the application, making it convenient to\nbroadcast notifications to disparate subsystems.  This is the recommended way\nof using notifications.\n\nIf desired, separate `NotificationCenter` instances can be created as well.\n\n    var nc = new notifications.NotificationCenter();\n    \nNotifications are only dispatched to observers registered with the\n`NotificationCenter` they are posted to.  Having separate `NotificationCenter`\ninstances allows notifications to be contained within subsystems of the\napplication.\n\n## Tests\n\n    $ npm install\n    $ make test\n\n[![Build Status](https://secure.travis-ci.org/jaredhanson/node-notifications.png)](http://travis-ci.org/jaredhanson/node-notifications)\n\n## Credits\n\n  - [Jared Hanson](http://github.com/jaredhanson)\n\nThis module is inspired by, and patterned closely after, the [NSNotificationCenter](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html)\nclass provided within Cocoa's Foundation Framework.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011 Jared Hanson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fnode-notifications","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fnode-notifications","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fnode-notifications/lists"}