# Connect to NATS

Show the messages of your NATS subjects and JetStream streams on the timeline.

Source: https://www.eventcatalog.dev/tools/streamview/docs/how-to/connect-to-nats

You need the `streamview` program, Node.js, and the address of a NATS server.

:::caution
The NATS adapter has no TLS options.
:::

## Show all subjects

Run this command with the address of your server:

```
streamview nats --servers localhost:4222
```

The first time, the command installs the NATS adapter. This takes some seconds.
The browser then opens, and each subject is one lane.

- For subjects that a JetStream stream stores, you see the history.
- For all other subjects, you see only the messages that come after streamview starts.

## Show only some subjects

Add `--subjects`, with a comma between the subjects. You can use the `*` and `>` wildcards.

```
streamview nats --servers localhost:4222 --subjects 'orders.>,payments.*'
```

## Make one lane from subjects that contain IDs

If your subjects contain IDs, there are too many lanes.
Add `--depth` with the number of subject parts that make one lane.

```
streamview nats --servers localhost:4222 --depth 2
```

With `--depth 2`, `telemetry.courier.7` and `telemetry.courier.8` are one lane, `telemetry.courier`.
The full subject stays in the `subject` field of each event.

## Show only new messages from streams

Add `--latest`. streamview then does not read the history of the streams.

To ignore JetStream fully, add `--no-jetstream`. streamview then subscribes to all subjects.

## Connect the messages of one order

Add `--correlation-field` with the name of the field that all messages of one order contain.

```
streamview nats --servers localhost:4222 --correlation-field orderId
```

streamview also reads the `correlationid` header, the `Correlation-Id` header, and the `traceparent` header of a message.

## Give a name and a password

Use one of these three options:

| The server needs | Add |
|---|---|
| A name and a password | `--user NAME --password TEXT` |
| A token | `--token TEXT` |
| A credentials file | `--creds FILE` |

:::note
We did not test these three options against a server that has authentication.
:::

## Related

- [Command line: `streamview nats`](https://www.eventcatalog.dev/tools/streamview/docs/reference/command-line#streamview-nats)
- [How streamview reads without taking messages](https://www.eventcatalog.dev/tools/streamview/docs/explanation/how-streamview-reads)
