{"id":22727274,"url":"https://github.com/noviel/cluster-launcher","last_synced_at":"2025-06-11T15:35:35.835Z","repository":{"id":57200966,"uuid":"81475922","full_name":"Noviel/cluster-launcher","owner":"Noviel","description":"Minimalistic multiprocess launcher for Node.js","archived":false,"fork":false,"pushed_at":"2017-02-15T18:26:39.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T02:17:14.068Z","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/Noviel.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":"2017-02-09T17:26:36.000Z","updated_at":"2017-02-15T18:19:43.000Z","dependencies_parsed_at":"2022-09-15T11:22:28.054Z","dependency_job_id":null,"html_url":"https://github.com/Noviel/cluster-launcher","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/Noviel%2Fcluster-launcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fcluster-launcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fcluster-launcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fcluster-launcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Noviel","download_url":"https://codeload.github.com/Noviel/cluster-launcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246260476,"owners_count":20748860,"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":"2024-12-10T17:11:35.042Z","updated_at":"2025-03-30T00:23:47.364Z","avatar_url":"https://github.com/Noviel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cluster multiprocess launcher\n\n## bI?\n\nMinimalistic configurable multiprocess launcher for Node.js based on cluster. Includes built-in sticky listeners for Socket.IO.\n\n## Installation\n\n`npm i cluster-launcher --save`\n\n## Usage\n\n```javascript\nconst {\n  launch,\n  stickyListenWorker,\n  stickyListenMaster\n} = require('cluster-launcher');\n\nconst workerFunc = (listen) =\u003e {\n  // Use express for example.\n  const app = require('express')();\n  const http = require('http').Server(app);\n\n  app.get('*', (req, res) =\u003e { \n    res.send(`Hello from worker pid:${process.pid}`); \n  });\n  listen(http);\n};\n\nconst masterFunc = (listen) =\u003e {\n  console.log('We are doing some crazy master stuff here!');\n  listen();\n};\n\nlaunch({\n  worker: {\n    main: workerFunc,\n    listen: stickyListenWorker\n  },\n  master: {\n    main: masterFunc,\n    listen: stickyListenMaster\n  },\n  config: {\n    threads: 4,\n    host: {\n      ip: 'localhost',\n      port: 5000\n    }\n  }\n});\n```\n\n## API\n\n### .launch(opts)\n@param opts { object } options object  \n\nExpected that master and worker will call `listen` by themselves, because they can contain some async init functions.\n\n##### Options object\n- **config** { object }  \n  - **threads** { number } count of worker processes to spawn. `default: 1`\n  - **host** { object } web server configuration\n    - **ip** { string } `default: 'localhost'`\n    - **port** { number } `default: 8080`\n- **worker**\n  - **main** { function } entry point of the every worker, takes `listen` as a parameter\n  - **listen** { function } `default: stickyListenWorker`\n- **master**\n  - **main** { function } entry point of the master\n  - **listen** { function } `default: stickyListenMaster`\n\n`worker`/`master`'s `main` will be called with specified to them listen function as a parameter.\n\n##### Worker's listen\nExpects `http` server object as a parameter.\n\n##### Master's listen \nWill be wrapped in a function that takes no arguments. Because of it in the master's `main` you should just do `listen()`. But inside it will be called by `launch` with options object as a parameter:\n- **ip** { string }\n- **port** { number }\n- **workers** { array }\n\n\n### .stickyListenWorker, .stickyListenMaster\nDefault built-in listen function for worker, that provide sticky connection for the client to \nspecific worker based on the client's ip address. Usefull for Socket.IO.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fcluster-launcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoviel%2Fcluster-launcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fcluster-launcher/lists"}