{"id":31908662,"url":"https://github.com/expressenab/exp-leader-election","last_synced_at":"2025-10-13T15:51:14.551Z","repository":{"id":4251781,"uuid":"51991792","full_name":"ExpressenAB/exp-leader-election","owner":"ExpressenAB","description":"Leader election for nodejs applications","archived":false,"fork":false,"pushed_at":"2021-11-03T11:49:51.000Z","size":46,"stargazers_count":8,"open_issues_count":2,"forks_count":7,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-09-22T18:40:32.272Z","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/ExpressenAB.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":"2016-02-18T08:22:14.000Z","updated_at":"2025-05-26T01:23:12.000Z","dependencies_parsed_at":"2022-08-23T18:20:16.851Z","dependency_job_id":null,"html_url":"https://github.com/ExpressenAB/exp-leader-election","commit_stats":null,"previous_names":["norla/exp-leader-election"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ExpressenAB/exp-leader-election","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpressenAB%2Fexp-leader-election","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpressenAB%2Fexp-leader-election/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpressenAB%2Fexp-leader-election/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpressenAB%2Fexp-leader-election/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpressenAB","download_url":"https://codeload.github.com/ExpressenAB/exp-leader-election/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpressenAB%2Fexp-leader-election/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015938,"owners_count":26085777,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-13T15:51:07.121Z","updated_at":"2025-10-13T15:51:14.546Z","avatar_url":"https://github.com/ExpressenAB.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leader election for nodejs applications\n\n[![Run tests](https://github.com/ExpressenAB/exp-leader-election/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ExpressenAB/exp-leader-election/actions/workflows/run-tests.yml)\n\nElect a leader among several nodes using consul.\n\nhttps://www.consul.io/docs/guides/leader-election.html\n\n## Usage\n\n### Basic example\n\nConnect to consul and get notified about leadership status.\n\n```javascript\nvar leaderElection = require(\"exp-leader-election\");\nvar service = require(\"my-little-service\");\n\nvar config = {\n  key: \"locks/my-little-service\",\n  consul : {\n    host: \"my.consul.hostname\"\n  }\n}\n\nleaderElection(config)\n.on(\"gainedLeadership\", function () {\n    // Whoo-hoo, we have been elected as leader! Do work.\n    service.startDoingWork();\n  })\n.on(\"error\", function () {\n   // Error occured, stop work.\n   log.error(\"Leader election error occured\", error);\n   service.stopDoingWork();\n  });\n```\n\n### The let-it-crash way\n\nIf you want your application to crash in case of leader election errors, just omit the\n\"error\" listener. This is the simplest and most robust way to deal with errors,\nbut it requires that you have a process manager (such as forever or pm2) in place to\nensure that the application is restarted again.\n\n## Configuration\n\n### Full Example\n\n```javascript\n{\n  key: \"locks/my-little-service\", // Only required option\n  debug: console.log,\n  consul: {\n    host: \"127.0.0.1\",\n    port: 8050,\n    token: \"asdpf2344d083udhd8723\",\n    ttl: 15,\n    lockDelay: 10,\n    readWait: 180\n  }\n}\n```\n### Consul\n\n* `consul.host`: Consul hostname or ip (string)\n* `consul.port`: Consul port (number)\n* `consul.ttl`: Tuning, session ttl seconds (number, default 15)\n* `consul.lockDelay`: Tuning, session lock-delay seconds (number, default 10)\n* `consul.readWait`: Tuning, read wait seconds (number, default 180)\n\nTo read more about the tuning parameters, see\nhttps://www.consul.io/docs/internals/sessions.html\n\n### Debugging\n\n* `debug`: function accepting a variable number of args. Supply if you want to print debugging info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressenab%2Fexp-leader-election","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpressenab%2Fexp-leader-election","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressenab%2Fexp-leader-election/lists"}