# node-red-contrib-mock-cli

> Allows running Node-RED modules from command-line.

Latest version **1.5.1** (published 2026-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-red-contrib-mock-cli
pnpm add node-red-contrib-mock-cli
yarn add node-red-contrib-mock-cli
bun add node-red-contrib-mock-cli
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2026-08-08 |
| First published | 2019-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Alexandre Alapetite |
| Maintainers | alkarex |
| Keywords | CLI, command-line, nodered, node-red |

## Links

- npm: https://www.npmjs.com/package/node-red-contrib-mock-cli
- Repository: https://github.com/alexandrainst/node-red-contrib-mock-cli
- Homepage: https://github.com/alexandrainst/node-red-contrib-mock-cli#readme
- Issues: https://github.com/alexandrainst/node-red-contrib-mock-cli/issues
- npm.io page: https://npm.io/package/node-red-contrib-mock-cli

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.5.1 (latest) — 2026-08-08
- 1.5.0 — 2026-08-08
- 1.4.4 — 2026-08-07
- 1.4.3 — 2024-08-02
- 1.4.2 — 2024-08-02
- 1.4.1 — 2023-10-13
- 1.4.0 — 2023-10-12
- 1.3.1 — 2023-10-11
- 1.3.0 — 2023-10-11
- 1.2.4 — 2023-10-11
- 1.2.3 — 2023-05-31
- 1.2.2 — 2023-01-09
- 1.2.1 — 2022-12-13
- 1.2.0 — 2022-02-02
- 1.1.1 — 2022-02-02
- … 11 more at https://npm.io/package/node-red-contrib-mock-cli/versions

## README

# node-red-contrib-mock-cli

This is a [Node.js](https://nodejs.org) module to allow running **a single** [Node-RED](https://nodered.org) node from command-line, and pipe one to another, using a similar flow than what would be done in the Node-RED graphical interface.

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/alexandrainst/node-red-contrib-mock-cli/nodejs.yml?branch=main&logo=github)
![npm](https://img.shields.io/npm/dy/node-red-contrib-mock-cli?logo=npm)

[![NPM statistics](https://nodei.co/npm/node-red-contrib-mock-cli.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/node-red-contrib-mock-cli/)

Originally made in December 2019 by [Alexandre Alapetite](https://alexandra.dk/alexandre.alapetite) at the [Alexandra Institute](https://alexandra.dk) for the [SynchroniCity European project](https://synchronicity-iot.eu).

License: [MIT](LICENSE.md)

See examples of use in [*node-red-contrib-json-multi-schema*](https://github.com/alexandrainst/node-red-contrib-json-multi-schema),
[*node-red-contrib-chunks-to-lines*](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines), [*node-red-http-basic-auth*](https://github.com/alexandrainst/node-red-http-basic-auth).

## Usage

Add an entry file `index.js` (or another name) to your Node-RED node, next to a `package.json` that contains a structure like `{ "node-red": {"node-type": "node-type.js"} }`:

```js
const RED = require('node-red-contrib-mock-cli');
const noderedNode = RED.load(require.main);
if (noderedNode) {
	//noderedNode.*	//Access to the Node-RED node instance
	RED.run();
} else {
	console.error('Error loading Node-RED node!');
}
```

One can then invoke the node from command-line, passing the node type first, and then some optional node properties in JSON format:

```sh
node ./index.js node-type --firstProperty='{"Some":"JSON"}' --secondProperty='"Some text"' --thirdProperty='123'
```

Properties of configuration nodes can be specified using a *dot* such as:

```sh
node ./index.js node-type --server.url='"https://example.net/"' --server.username='"Alice"'
```

### Example

Replace `test.js` by the name of your entry file (e.g. `index.js`), and `test-node` by the name of the type of your node.

```sh
printf '{"payload":3} \n {"payload":7}' | node ./test.js test-node --multiplyBy='5'
```

Outputs:

```json
{"payload":15}
{"payload":35}
```

### JSON in Node-RED format

The command expects JSON messages with a Node-RED structure `{"payload":"Example"}` from standard input, one line per message.

[`jq`](https://stedolan.github.io/jq/) may be used to break down and format a standard payload into a Node-RED payload:

For instance if the input is a list of observations wrapped into a JSON array:

```sh
jq -c '.[] | {"payload":.}'
```

The command outputs JSON messages with a Node-RED structure to standard output, one line per message.

See some examples of inputs and outputs in [*node-red-contrib-json-multi-schema*](https://github.com/alexandrainst/node-red-contrib-json-multi-schema#wiringpiping-all-modules-together).

### Standard outputs

Only the Node-RED JSON payload is emitted on standard-output (STDOUT), while all other messages and errors are on the standard-error (STDERR).


### Advanced usage

It is possible to catch the node events { `debug`, `error`, `log` } to override the default behaviour (which is to write to standard-error):

```js
noderedNode.on('debug', msg => console.warn('Caught event: ' + msg));
```


## Limitations

This module does not have the ambition of exposing the full Node-RED functionality, but instead focuses on simple cases, providing a tiny and efficient layer without any dependency.
So for more advanced unit testing, and if requiring the full Node-RED is fine, then check the official [node-red-node-test-helper](https://github.com/node-red/node-red-node-test-helper) instead of this module.

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