nats.docs icon indicating copy to clipboard operation
nats.docs copied to clipboard

Nats documentation for javascript and typescript outdated

Open lukadriel7 opened this issue 2 years ago • 2 comments

Hello, I was following the documentation on nats for typescript but the code is completely outdated. An example would be the code for asynchronous subscription: Docs version:

nc.subscribe("updates", (err, msg) => {
    if(err) {
        console.log('error', err);
    } else {
        t.log(msg.data);
    }
});

Library repository version

const { connect, StringCodec } = require("nats");

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
// create a codec
const sc = StringCodec();
// create a simple subscriber and iterate over messages
// matching the subscription
const sub = nc.subscribe("hello");
(async () => {
  for await (const m of sub) {
    console.log(`[${sub.getProcessed()}]: ${sc.decode(m.data)}`);
  }
  console.log("subscription closed");
})();

Is there any plan to update the docs for these ?

lukadriel7 avatar Sep 15 '21 19:09 lukadriel7

👋 hello @lukadriel7 ! Yes, just speaking of this yesterday. Our engineer just updated the examples in the repo but they have not been populated to docs yet. You can find the repo here https://github.com/nats-io/node-nats-examples

gcolliso avatar Sep 15 '21 20:09 gcolliso

@gcolliso Thank you very much, I will take a look

lukadriel7 avatar Sep 15 '21 20:09 lukadriel7