edgeport - v1.0.3
    Preparing search index...

    Function connect

    • Connects to a NATS server, authenticates, and returns a live connection.

      Dials the core transport (implicit TLS when tls: 'implicit', otherwise plaintext that may be upgraded), reads the server INFO, performs a STARTTLS-style upgrade when requested or required, sends CONNECT + PING, and waits for PONG so an auth failure surfaces here as AuthError. A background pump then routes incoming messages to subscriptions.

      Parameters

      Returns Promise<NatsConnection>

      The live connection.

      If the server rejects the credentials.

      If the connection cannot be established.

      If the server speaks the protocol incorrectly.

      If the handshake exceeds the deadline.

      1.0.0

      import { connect } from 'edgeport/nats';

      await using nc = await connect({ hostname: 'nats.example.com', token: 'secret' });
      await using sub = nc.subscribe('updates.>');
      await nc.publish('updates.temp', '21.5');
      for await (const msg of sub) {
      console.log(msg.subject, new TextDecoder().decode(msg.data));
      break;
      }