# xyz-cli

> Command line tool dor node xyz

Latest version **0.4.2** (published 2017-05-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install xyz-cli
pnpm add xyz-cli
yarn add xyz-cli
bun add xyz-cli
```

Provides the command `xyz`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2017-05-08 |
| First published | 2016-12-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 15 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kian Peymani @Kianenigma |
| Maintainers | kianenigma |
| Keywords | microservice, node, nodexyz |

## Links

- npm: https://www.npmjs.com/package/xyz-cli
- npm.io page: https://npm.io/package/xyz-cli

## Dependencies (15)

- [clui](https://npm.io/package/clui.md) ^0.3.1
- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [clear](https://npm.io/package/clear.md) 0.0.1
- [touch](https://npm.io/package/touch.md) ^1.0.0
- [figlet](https://npm.io/package/figlet.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [marked](https://npm.io/package/marked.md) latest
- [vorpal](https://npm.io/package/vorpal.md) ^1.11.4
- [inquirer](https://npm.io/package/inquirer.md) ^1.1.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [xyz-core](https://npm.io/package/xyz-core.md) ^0.4.1
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [always-tail](https://npm.io/package/always-tail.md) ^0.2.0
- [preferences](https://npm.io/package/preferences.md) ^0.2.1
- [marked-terminal](https://npm.io/package/marked-terminal.md) latest

## 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

- 0.4.2 (latest) — 2017-05-08
- 0.4.1 — 2017-04-02
- 0.4.0 — 2017-03-31
- 0.3.3 — 2017-03-13
- 0.3.2 — 2017-03-03
- 0.3.1 — 2017-02-25
- 0.3.0 — 2017-01-26
- 0.1.0 — 2016-12-29

## README

# xyz-cli

[![Build Status](https://travis-ci.org/node-xyz/xyz-cli.svg?branch=master)](https://travis-ci.org/node-xyz/xyz-cli) [![npm version](https://badge.fury.io/js/xyz-cli.svg)](https://badge.fury.io/js/xyz-cli)
---

Command line Interface for node-xyz

# Usage

xyz-cli can be installed using

```bash
$ npm install -g xyz-cli
```

The cli app is `xyz` and should be available in your command line environment.

# Commands

- ### dev

This command is the most useful one in xyz-cli. It runs a set of xyz-core instances according to a config file.

```bash
xyz dev [options] [xyzCommandLineArgs...]
```

where options can be:

| option (short and  long form)         | default value  | Description |
| :------------- | :------------- | :----------|
| -c --config|  `./xyzrc.json` | the config file to use when running microservices. More information is given below |
| -e --errlog    | false       | will print the logs of each service in the init phase to terminal, even of `stdout` is set to false in the config file. |
| -x --xyzadmin  | false       | will create a new `xyz-core` instance inside the cli process. More information given below |
| -d --delay <value> |  500  | the delay between spawning new processes in milliseconds. |

`xyzCommandLineArgs` can be an optional set of parameters passed to the xyz-core instance created inside the cli process. Hence, this works only when `-x` is activated. They act exactly like passing `--xyz-` prefixed arguments to a single process. The main difference is that in this case `--` **MUST** be omitted.

Example:

```xyz dev -x -c ./xyzrc.json xyz-name my-cli-node xyz-transport.0.port 8000```

In this case, aside from whatever that is inside the config file, a new xyz-core instance will be creted with name **_my-cli-node_** and on port 8000


#### The Config File

The config file should be json file with the following format:

```json
{
  "nodes": [
    {
      "path": "path/to/my/file.js",
      "instance": 2,
      "port": 5000,
      "increment": 100,
      "stdio": "console",
      "params": ""
    },
    ...
  ]
}
```

Where the keys cna be:

| Key name | Description     |
| :------------- | :------------- |
| path       | path to the `.js` file relative to where `xyz` command is running       |
| instance   | The number of instances to create |
| port       | starting port for this set of instances. `xyz-cli` will automatically override the port given in `selfConf`. |
| increment   | increment value in port when `instance` is more than one |
| stdio     | destination of the node's output. can be `console` or `file`. if file is selected, the node's output will be written to a file with appropriate name in a new folder named `log` relative to where the `.js` file is.|  
| params    | values passed to the process as `process.argv`. can be anything with `--xyz` prefix similar to how a single ndoe's configuration can be overwritten with command line arguments.|
| env | environemtns variables passed to the process.|

As an example, the above code will generate two `file.js` nodes, one in port 5000 and the other in 5100.

> xyz-cli will only override the port of the first server. The rest should be handled by the developer.

> If you set `stdio` to `console`, everything will be printed to just one terminal. This might get messy and using the rest of the commands is near to impossible.

for the rest of this document we will use the two files in `exampels` folder of this repository as an example. The config file is:

```json
{
  "nodes": [
    {
      "path": "string.ms.js",
      "instance": 3,
      "port": 5000,
      "increment": 100,
      "stdio": "file",
      "params": "--xyz-logLevel verbose --xyz-seed 127.0.0.1:4000"
    },
    {
      "path": "math.ms.js",
      "instance": 1,
      "port": 4000,
      "stdio": "file",
      "params": "--xyz-logLevel verbose --xyz-name math.ms.master"
    },
    {
      "path": "math.ms.js",
      "instance": 1,
      "port": 6000,
      "stdio": "file",
      "env": "foo bar"
      "params": "--xyz-logLevel verbose --xyz-seed 127.0.0.1:4000 --xyz-name math.ms.slave"
    }
  ]
}
```

- ### ls

After a successful `dev` command, it will list all running nodes. For the previous example it will print:

![ls](https://github.com/node-xyz/xyz-cli/blob/master/media/ls.png?raw=true)

- ### top

Will print the live updates of the nodes usage. Example:

![top](https://github.com/node-xyz/xyz-cli/blob/master/media/top.png?raw=true)

- ### inspect `<identifier>`

will print all of the information that were printed using `console.log` in the main program. Example:

![inspect](https://github.com/node-xyz/xyz-cli/blob/master/media/insp.png?raw=true)

Identifier can be the **index** or **identifier** mentioned in the `ls` command. As an example, both `inspect 0` and `inspect string.ms@127.0.0.1:5000` are valid.

> All of the commands that accept an `<identifier>` as argument have the same rule as above.

- ### inspectJSON `<identifier>`

Will return all of the information in `inspect`

- ### inspectSelf

Will inspect the cli's node. Will work only when -x is active.

- ### log `<identifier>`

Will start logging the output of a specific microservice to the terminal. It is useful only when `stdio` in the config file is set to `file`.

- ### kill `<identifier>`

Kills a specific node.

- ### restart `<identifier>`

Will restart a specific node. useful while development.

- ### duplicate `<identifier>`

Will duplicate a specific node. This will create an **Identical** node with the same configurations, except the `port`. it will automatically increment the port of the source node util it finds an empty port for the new node (This might cause some problems if each node is having multiple servers)


- ### msg `<identifier> <servicePath> [payload]`

Will send a message to `<indentifier>` using `<servicePath>` with an optional payload `[payload]`. This will only work when you run services with `-x` and all nodes use the default ping as their service discovery mechanism.

# The admin node (`dev -x`)

This option can be enabled to create a `xyz-core` instance inside the cli. This node will automatically expose some services so that other cli nodes (or basically any other client) can use them:

```bash
Services:
  anonymousFN @ /node/get
  anonymousFN @ /node/create
  anonymousFN @ /node/restart
  anonymousFN @ /node/kill
  anonymousFN @ /node/duplicate
  anonymousFN @ /node/inspect
  anonymousFN @ /node/inspectJSON
```

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