Connecting to the Default Server

    Go

    1. Connection nc = Nats.connect();
    2. // Do something with the connection
    3. nc.close();

    JavaScript

    1. nc = NATS()
    2. await nc.connect()
    3. await nc.close()

    Ruby

    1. // will throw an exception if connection fails
    2. let nc = await connect();
    3. // Do something with the connection
    4. // When done close it
    5. nc.close();
    6. // alternatively, you can use the Promise pattern
    7. let nc1: Client;
    8. connect()
    9. .then((c) => {
    10. nc1 = c;
    11. // Do something with the connection
    12. nc1.close();
    13. // add a .catch/.finally

    C