{"id":16707847,"url":"https://github.com/syuilo/xev","last_synced_at":"2025-10-04T05:43:39.241Z","repository":{"id":57401328,"uuid":"87483038","full_name":"syuilo/xev","owner":"syuilo","description":"Node.js Global Event System","archived":false,"fork":false,"pushed_at":"2022-04-17T05:41:24.000Z","size":29,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T19:41:31.069Z","etag":null,"topics":["nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/syuilo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-04-06T23:07:55.000Z","updated_at":"2024-06-11T05:01:18.000Z","dependencies_parsed_at":"2022-09-19T04:50:23.114Z","dependency_job_id":null,"html_url":"https://github.com/syuilo/xev","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syuilo%2Fxev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syuilo%2Fxev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syuilo%2Fxev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syuilo%2Fxev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syuilo","download_url":"https://codeload.github.com/syuilo/xev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221818448,"owners_count":16885754,"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":["nodejs","typescript"],"created_at":"2024-10-12T19:41:14.083Z","updated_at":"2025-10-04T05:43:34.199Z","avatar_url":"https://github.com/syuilo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"xev\n================================================================\n\n[![][npm-badge]][npm-link]\n[![][travis-badge]][travis-link]\n[![][mit-badge]][mit]\n\nGlobal event system for [Node](https://github.com/nodejs/node).\n**It works well on the cluster!** (Messaging between master and workers)\n\nInstall\n----------------------------------------------------------------\n``` shell\n$ npm install xev --save\n```\n\nUsage\n----------------------------------------------------------------\nIt is the same as using [EventEmitter](https://nodejs.org/api/events.html).\n**But all events are shared globally.**\n\n### Simple usage\nFile A:\n``` javascript\nimport Xev from 'xev';\n\nconst ev = new Xev();\n\nev.on('my-event', message =\u003e {\n\tconsole.log(`message received: ${message}`);\n});\n```\n\nFile B:\n``` javascript\nimport Xev from 'xev';\n\nconst ev = new Xev();\n\nev.emit('my-event', 'yo'); // \u003c= 'message received: yo'\n```\n\n### On the cluster\nIf you use the cluster, You must be call `mount` function at the master process. e.g.:\n``` javascript\nimport { isMaster } from 'cluster';\nimport Xev from 'xev';\n\nconst ev = new Xev();\n\nif (isMaster) {\n\t// your master code\n\n\tev.mount(); // Init xev\n} else {\n\t// your worker code\n}\n```\n\nWorker A:\n``` javascript\nimport Xev from 'xev';\n\nconst ev = new Xev();\n\nev.on('my-event', message =\u003e {\n\tconsole.log(`message received: ${message}`);\n});\n```\n\nWorker B:\n``` javascript\nimport Xev from 'xev';\n\nconst ev = new Xev();\n\nev.emit('my-event', 'yo'); // \u003c= 'message received: yo'\n```\n\nTechnically, Node.js **cannot** workers to communicate directly\nwith each other - all communication goes via the master.\nSo, you must be call our `mount` initialize function.\n\n### That is it.\nGood luck, have fun.\n\nAPI\n----------------------------------------------------------------\nPlease see [EventEmitter](https://nodejs.org/api/events.html).\nIn the following, we will describe the unique API of xev.\n\n### new Xev(namespace?)\nIf you are a library developer, we recommend setting namespace\nto avoid conflicts with events of users or other libraries:\n``` javascript\nimport Xev from 'xev';\n\nconst ev = new Xev('my-namespace');\n```\n\n### xev.mount()\nIf you want to share events on the cluster, please call this method once in the master process.\n\nLicense\n----------------------------------------------------------------\n[MIT](LICENSE)\n\n[npm-link]:        https://www.npmjs.com/package/xev\n[npm-badge]:       https://img.shields.io/npm/v/xev.svg?style=flat-square\n[mit]:             http://opensource.org/licenses/MIT\n[mit-badge]:       https://img.shields.io/badge/license-MIT-444444.svg?style=flat-square\n[travis-link]:    https://travis-ci.org/syuilo/xev\n[travis-badge]:   http://img.shields.io/travis/syuilo/xev.svg?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyuilo%2Fxev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyuilo%2Fxev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyuilo%2Fxev/lists"}