{"id":22164363,"url":"https://github.com/remie/followtheleader","last_synced_at":"2025-07-26T10:33:06.759Z","repository":{"id":57239736,"uuid":"145809003","full_name":"remie/followtheleader","owner":"remie","description":"Zero-conf leader election based on bonjour","archived":false,"fork":false,"pushed_at":"2019-03-29T14:21:54.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T03:51:56.119Z","etag":null,"topics":["bonjour","elections","leader","leader-election","nodejs","typescript","zeroconf"],"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/remie.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":"2018-08-23T06:12:53.000Z","updated_at":"2020-06-12T13:55:47.000Z","dependencies_parsed_at":"2022-08-29T21:23:10.829Z","dependency_job_id":null,"html_url":"https://github.com/remie/followtheleader","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remie%2Ffollowtheleader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remie%2Ffollowtheleader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remie%2Ffollowtheleader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remie%2Ffollowtheleader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remie","download_url":"https://codeload.github.com/remie/followtheleader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227674031,"owners_count":17802303,"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":["bonjour","elections","leader","leader-election","nodejs","typescript","zeroconf"],"created_at":"2024-12-02T05:07:03.896Z","updated_at":"2024-12-02T05:07:06.343Z","avatar_url":"https://github.com/remie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Follow the Leader!\n\nThe zero-conf leader election library using Bonjour for service discovery.\n\n[![CircleCI](https://circleci.com/gh/remie/followtheleader.svg?style=svg)](https://circleci.com/gh/remie/followtheleader)\n\n## Installation\n\n```\nnpm install followtheleader -S\n```\n\n## Usage\n\n```typescript\nimport { elect, Elector } from 'followtheleader';\n\nconsole.log('Starting leader election');\nconst elector: Elector = elect(\"MyServiceName\");\nelector.on('leader', () =\u003e {\n  console.log('This node was elected as leader');\n});\nelector.on('follower', () =\u003e {\n  console.log('this node was elected as follower');\n});\nelector.on('reelection', () =\u003e {\n  console.log('master node is unavailable, restarting election process');\n});\nelector.on('error', (error) =\u003e {\n  console.log(error);\n});\nelector.start();\n```\n\n## API\n\n### Initializing\n\n```typescript\n// ES6\nimport { elect, Elector } from 'followtheleader';\nconst elector = elect(options));\n\n// CommonJS\nconst ftl = require('followtheleader');\nconst elector = ftl.elect(options);\n```\n\noptions are:\n\n- `name` (string, required)\n- `type` (string, optional) - defaults to 'udp'\n- `port` (number, optional) - defaults to 9001\n- `host` (string, optional) - defaults to '0.0.0.0'\n- `maxFailedResponses` (number, optional) - defaults to 3\n\nThe option values can either by provided as arguments or as an object.\n\n### Starting election process\n\n#### `elector.start()`\n\nStarts the election process. \nIf the node is elected leader it will start a heartbeat monitor that binds an UDP listener to the specified `port` and `host`. \nIf the node is elected follower, it will ping the master node. If `maxFailedResponses` is reached, the node will restart the election process.\n\n#### `Event: leader`\n\nThe node has been elected leader.\n\n#### `Event: follower`\n\nThe node has been elected follower.\n\n#### `Event: reelection`\n\nThe master node has become unavailable and the election process is restarted.\n\n#### `Event: error`\n\nAn error occurred somewhere during the election proces or in the heartbeat monitor.\n\n## Caveats\n\nZero-conf / Bonjour / mDNS service discovery will only work for nodes that are on the same network subnet mask. If your nodes run on servers spreading multiple geographical locations, on different networks or if you are using a diffferent VLAN per server, you should look for other solutions. A good alternative would be [Elector](https://www.npmjs.com/package/elector) which uses ZooKeeper.\n\nIf you are running your application in Amazon Web Services ECS clusters, you might want to try configuring your tasks with the `awsvpc` network mode. This will give each task their own elastic IP within the selected VPC subnet. This will only work if all ECS nodes are running in the same Availability Zone and subnet. If your cluster is running nodes in multiple Availability Zones, Zero-config/Bonjour/mDNS will not work.\n\nIf you're running Kubernetes, you should look into the [Kubernetes/Contrib election solution](https://github.com/kubernetes/contrib/tree/master/election).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremie%2Ffollowtheleader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremie%2Ffollowtheleader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremie%2Ffollowtheleader/lists"}