mirror of
https://github.com/hanzomsg/nats.js.git
synced 2026-10-30 20:31:36 +00:00
Reworked errors - removed NatsError --------- Signed-off-by: Alberto Ricart <[email protected]>
46 lines
886 B
JavaScript
Executable File
46 lines
886 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const process = require("node:process");
|
|
const parse = require("minimist");
|
|
const { connect } = require("../index");
|
|
|
|
const argv = parse(
|
|
process.argv.slice(2),
|
|
{
|
|
alias: {
|
|
"s": ["server"],
|
|
},
|
|
default: {
|
|
s: "127.0.0.1:4222",
|
|
},
|
|
},
|
|
);
|
|
|
|
const opts = { servers: argv.s, maxReconnectAttempts: -1 };
|
|
|
|
(async () => {
|
|
let nc;
|
|
try {
|
|
nc = await connect(opts);
|
|
} catch (err) {
|
|
console.log(`error connecting to nats: ${err.message}`);
|
|
return;
|
|
}
|
|
console.info(`connected ${nc.getServer()}`);
|
|
|
|
let counter = 0;
|
|
(async () => {
|
|
for await (const s of nc.status()) {
|
|
counter++;
|
|
console.info(`${counter} ${s.type}: ${JSON.stringify(s.data)}`);
|
|
}
|
|
})().then();
|
|
|
|
await nc.closed()
|
|
.then((err) => {
|
|
if (err) {
|
|
console.error(`closed with an error: ${err.message}`);
|
|
}
|
|
});
|
|
})();
|