# sendmessage

> Send a cross process message if message channel is connected.

Latest version **3.0.2** (published 2025-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install sendmessage
pnpm add sendmessage
yarn add sendmessage
bun add sendmessage
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2025-09-27 |
| First published | 2014-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18.19.0 |
| Dependencies | 0 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 27 |
| Author | fengmk2 |
| Maintainers | fengmk2 |
| Keywords | sendmessage, send, cluster, message, channel closed |

## Links

- npm: https://www.npmjs.com/package/sendmessage
- Repository: https://github.com/node-modules/sendmessage
- Issues: https://github.com/node-modules/sendmessage/issues
- npm.io page: https://npm.io/package/sendmessage

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2025-09-27
- 3.0.1 — 2024-12-11
- 3.0.0 — 2024-06-23
- 2.0.0 — 2023-06-13
- 1.1.0 — 2016-11-02
- 1.0.5 — 2015-04-14
- 1.0.4 — 2014-12-03
- 1.0.3 — 2014-11-21
- 1.0.2 — 2014-11-21
- 1.0.1 — 2014-11-14
- 1.0.0 — 2014-11-14

## README

# sendmessage

[![NPM version][npm-image]][npm-url]
[![CI](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/sendmessage.svg?style=flat-square
[npm-url]: https://npmjs.org/package/sendmessage
[download-image]: https://img.shields.io/npm/dm/sendmessage.svg?style=flat-square
[download-url]: https://npmjs.org/package/sendmessage
[codecov-image]: https://codecov.io/gh/node-modules/sendmessage/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/sendmessage

Send a cross process message if message channel is connected.
Avoid [channel closed](https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/child_process.js#L411) error throw out.

## Install

```bash
npm install sendmessage --save
```

## Usage

### master.js

```ts
import { fork } from 'node:child_process';
import { sendmessage } from 'sendmessage';

const worker = fork('./worker.js');

sendmessage(worker, { hi: 'this is a message to worker' });
```

### worker.js

```ts
import { sendmessage } from 'sendmessage';

sendmessage(process, { hello: 'this is a message to master' });
```

## API

### #sendmessage(childProcess, message)

Send a cross process message.
If a process is not child process, this will just call `process.emit('message', message)` instead.

- childProcess: child process instance
- message: the message need to send

```js
sendmessage(process, { hello: 'this is a message to master' });
```

You can switch to `process.emit('message', message)` using `process.env.SENDMESSAGE_ONE_PROCESS`

## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=node-modules/sendmessage)](https://github.com/node-modules/sendmessage/graphs/contributors)

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

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