> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nats-io/nats-server/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart guide

> Get started with NATS Server in minutes - install, run, and send your first message

This quickstart guide will help you get NATS Server up and running and send your first message in just a few minutes.

## Prerequisites

No special prerequisites are required. NATS Server is a single binary with no external dependencies.

## Get started

<Steps>
  <Step title="Install NATS Server">
    The fastest way to get started is using Docker:

    ```bash theme={null}
    docker pull nats:latest
    ```

    Alternatively, download the binary for your platform from the [GitHub releases page](https://github.com/nats-io/nats-server/releases/).

    For other installation methods, see the [installation guide](/installation).
  </Step>

  <Step title="Start the server">
    Start NATS Server with default settings:

    <CodeGroup>
      ```bash Docker theme={null}
      docker run -p 4222:4222 -p 8222:8222 nats:latest
      ```

      ```bash Binary theme={null}
      nats-server
      ```
    </CodeGroup>

    You should see output indicating the server is running:

    ```
    [1] 2026/03/04 12:00:00.000000 [INF] Starting nats-server
    [1] 2026/03/04 12:00:00.000000 [INF]   Version:  2.x.x
    [1] 2026/03/04 12:00:00.000000 [INF]   Git:      [not set]
    [1] 2026/03/04 12:00:00.000000 [INF]   Listening for client connections on 0.0.0.0:4222
    [1] 2026/03/04 12:00:00.000000 [INF]   Server is ready
    ```

    <Info>
      The default client port is **4222**. The monitoring port is **8222** when enabled with `-m 8222`.
    </Info>
  </Step>

  <Step title="Install the NATS CLI (optional)">
    For testing, install the NATS CLI tool:

    ```bash theme={null}
    # macOS
    brew install nats-io/nats-tools/nats

    # Linux/macOS (using curl)
    curl -sf https://binaries.nats.dev/nats-io/natscli/nats@latest | sh

    # Windows (using chocolatey)
    choco install nats
    ```

    The NATS CLI is also included in the Docker image at `/bin/nats`.
  </Step>

  <Step title="Subscribe to a subject">
    Open a new terminal and subscribe to a test subject:

    <CodeGroup>
      ```bash NATS CLI theme={null}
      nats sub test.subject
      ```

      ```bash Docker theme={null}
      docker exec -it <container-id> nats sub test.subject
      ```
    </CodeGroup>

    You should see:

    ```
    12:00:00 Subscribing on test.subject
    ```

    Leave this terminal open to receive messages.
  </Step>

  <Step title="Publish a message">
    In another terminal, publish a message:

    <CodeGroup>
      ```bash NATS CLI theme={null}
      nats pub test.subject "Hello NATS!"
      ```

      ```bash Docker theme={null}
      docker exec -it <container-id> nats pub test.subject "Hello NATS!"
      ```
    </CodeGroup>

    In the subscriber terminal, you should see the message:

    ```
    12:00:05 [#1] Received on "test.subject"
    Hello NATS!
    ```

    <Tip>
      Try publishing multiple messages and watch them appear in real-time in the subscriber terminal!
    </Tip>
  </Step>

  <Step title="Verify server status">
    Check the server monitoring endpoint:

    ```bash theme={null}
    curl http://localhost:8222/varz
    ```

    This returns JSON with server statistics including connections, message counts, and memory usage.

    <Note>
      The monitoring endpoint must be enabled with `-m 8222` when starting the server, or configured in the configuration file with `monitor_port: 8222`.
    </Note>
  </Step>
</Steps>

## Common server options

Here are some commonly used command-line options:

```bash theme={null}
# Bind to specific address and port
nats-server -a 127.0.0.1 -p 4222

# Enable monitoring
nats-server -m 8222

# Enable JetStream with storage directory
nats-server -js --store_dir /data/nats

# Use configuration file
nats-server -c /path/to/nats-server.conf

# Enable debug logging
nats-server -D

# Enable authentication
nats-server --user admin --pass secret
```

<Info>
  For a complete list of options, run `nats-server --help` or see the [configuration reference](/configuration/server-options).
</Info>

## Testing with client libraries

NATS has client libraries for over 40 programming languages. Here's a quick example in a few popular languages:

<CodeGroup>
  ```go Go theme={null}
  package main

  import (
      "log"
      "github.com/nats-io/nats.go"
  )

  func main() {
      nc, err := nats.Connect(nats.DefaultURL)
      if err != nil {
          log.Fatal(err)
      }
      defer nc.Close()

      // Subscribe
      nc.Subscribe("test.subject", func(m *nats.Msg) {
          log.Printf("Received: %s", string(m.Data))
      })

      // Publish
      nc.Publish("test.subject", []byte("Hello NATS!"))
      nc.Flush()
  }
  ```

  ```javascript Node.js theme={null}
  const { connect } = require('nats');

  async function main() {
      const nc = await connect({ servers: 'nats://localhost:4222' });

      // Subscribe
      const sub = nc.subscribe('test.subject');
      (async () => {
          for await (const msg of sub) {
              console.log('Received:', msg.string());
          }
      })();

      // Publish
      nc.publish('test.subject', 'Hello NATS!');

      await nc.drain();
  }

  main();
  ```

  ```python Python theme={null}
  import asyncio
  from nats.aio.client import Client as NATS

  async def main():
      nc = NATS()
      await nc.connect("nats://localhost:4222")

      # Subscribe
      async def message_handler(msg):
          print(f"Received: {msg.data.decode()}")

      await nc.subscribe("test.subject", cb=message_handler)

      # Publish
      await nc.publish("test.subject", b"Hello NATS!")
      await nc.flush()

      await nc.close()

  if __name__ == '__main__':
      asyncio.run(main())
  ```
</CodeGroup>

## Next steps

Now that you have NATS Server running, explore these topics:

<CardGroup cols={2}>
  <Card title="Configuration" icon="gear" href="/deployment/configuration">
    Learn how to configure NATS Server for production
  </Card>

  <Card title="JetStream" icon="stream" href="/features/jetstream">
    Enable persistence and streaming with JetStream
  </Card>

  <Card title="Clustering" icon="network-wired" href="/architecture/clustering">
    Set up high availability with clustering
  </Card>

  <Card title="Security" icon="lock" href="/operations/security">
    Secure your NATS deployment
  </Card>
</CardGroup>

## Troubleshooting

<Accordion title="Connection refused errors">
  Ensure the server is running and listening on the correct port (default 4222). Check firewall settings if connecting from a different machine.
</Accordion>

<Accordion title="Server won't start">
  Check if another process is using port 4222. Use `nats-server -p 4223` to use a different port. Enable debug logging with `-D` for more information.
</Accordion>

<Accordion title="Messages not being received">
  Verify the subscriber is connected before publishing. Check that subject names match exactly (they are case-sensitive).
</Accordion>

## Get help

If you need assistance:

* Join the [NATS Community Slack](https://slack.nats.io)
* Ask questions on [Google Groups](https://groups.google.com/forum/#!forum/natsio)
* Check the [FAQ](https://docs.nats.io/reference/faq)
