# egg-cluster

> cluster manager for egg

Latest version **2.5.0** (published 2025-12-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-cluster
pnpm add egg-cluster
yarn add egg-cluster
bun add egg-cluster
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: no vulnerabilities; has provenance.

Warnings: low downloads; no types; no esm support.

Negative: declining downloads.

## Facts

| | |
|---|---|
| Version | 2.5.0 |
| Published | 2025-12-13 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 14.0.0 |
| Dependencies | 13 |
| Unpacked size | 61.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 222 |
| Author | dead-horse |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, hyj1991, killagu, coolme200, akitasummer, dead_horse, popomore |
| Keywords | egg, cluster, process |

## Links

- npm: https://www.npmjs.com/package/egg-cluster
- Repository: https://github.com/eggjs/cluster
- Homepage: https://github.com/eggjs/cluster#readme
- Issues: https://github.com/eggjs/cluster/issues
- npm.io page: https://npm.io/package/egg-cluster

## Dependencies (13)

- [cfork](https://npm.io/package/cfork.md) ^1.7.1
- [ps-tree](https://npm.io/package/ps-tree.md) ^1.2.0
- [utility](https://npm.io/package/utility.md) ^1.15.0
- [egg-utils](https://npm.io/package/egg-utils.md) ^2.4.1
- [get-ready](https://npm.io/package/get-ready.md) ^2.0.1
- [egg-logger](https://npm.io/package/egg-logger.md) ^3.3.0
- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.1
- [await-event](https://npm.io/package/await-event.md) ^2.1.0
- [detect-port](https://npm.io/package/detect-port.md) ^2.0.1
- [sendmessage](https://npm.io/package/sendmessage.md) ^1.1.0
- [terminal-link](https://npm.io/package/terminal-link.md) ^2.1.1
- [cluster-reload](https://npm.io/package/cluster-reload.md) ^1.0.2
- [graceful-process](https://npm.io/package/graceful-process.md) ^1.2.0

## Recent versions

- 2.5.0 (latest) — 2025-12-13
- 2.4.0-beta.0 (beta) — 2024-10-26
- 2.5.0-beta.3 — 2025-12-12
- 2.5.0-beta.2 — 2025-12-12
- 2.5.0-beta.1 — 2025-12-12
- 2.5.0-beta.0 — 2025-12-12
- 2.4.0 — 2024-12-09
- 2.3.0 — 2024-06-03
- 2.2.1 — 2023-12-08
- 2.2.0 — 2023-06-27
- 2.1.1 — 2023-06-06
- 2.1.0 — 2023-05-31
- 2.0.1 — 2022-12-19
- 2.0.0 — 2022-11-02
- 1.27.1 — 2021-11-15
- … 56 more at https://npm.io/package/egg-cluster/versions

## README

# egg-cluster

[![NPM version][npm-image]][npm-url]
[![CI](https://github.com/eggjs/cluster/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/cluster/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-cluster.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-cluster
[codecov-image]: https://codecov.io/github/eggjs/cluster/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/cluster?branch=master
[snyk-image]: https://snyk.io/test/npm/egg-cluster/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-cluster
[download-image]: https://img.shields.io/npm/dm/egg-cluster.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-cluster

Cluster Manager for EggJS

---

## Install

```bash
npm i egg-cluster --save
```

## Usage

```js
const startCluster = require('egg-cluster').startCluster;
startCluster({
  baseDir: '/path/to/app',
  framework: '/path/to/framework',
});
```

You can specify a callback that will be invoked when application has started. However, master process will exit when catch an error.

```js
startCluster(options, () => {
  console.log('started');
});
```

## Options

| Param        | Type      | Description                              |
| ------------ | --------- | ---------------------------------------- |
| baseDir      | `String`  | directory of application                 |
| framework    | `String`  | specify framework that can be absolute path or npm package |
| plugins      | `Object`  | plugins for unittest                     |
| workers      | `Number`  | numbers of app workers                   |
| sticky       | `Boolean` | sticky mode server                       |
| port         | `Number`  | port                                     |
| reusePort   | `Boolean` | (Required Node.js >= 22.12.0) allows multiple sockets on the same host to bind to the same port. Incoming connections are distributed by the operating system to listening sockets. This option is available only on some platforms, such as Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+. **Default:** `false` |
| debugPort    | `Number`  | the debug port only listen on http protocol |
| https        | `Object`  | start a https server, note: `key` / `cert` / `ca` should be full path to file |
| require      | `Array\|String` | will inject into worker/agent process |
| pidFile      | `String`  | will save master pid to this file |
| startMode    | `String`  | default is 'process', use 'worker_threads' to start the app & agent worker by worker_threads |
| ports        | `Array`   | startup port of each app worker, such as: [7001, 7002, 7003], only effects when the `startMode` is `'worker_threads'` and `reusePort` is `false` |
| env        | `String`   | custom env, default is process.env.EGG_SERVER_ENV |

## Env

EGG_APP_CLOSE_TIMEOUT: app worker boot timeout value

EGG_AGENT_CLOSE_TIMEOUT: agent worker boot timeout value

## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/cluster)](https://github.com/eggjs/cluster/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).

---
_Source: https://npm.io/package/egg-cluster · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
