Dev Helpers
← Back

Collect a published payload

Collect a published payload using Node.js.

Open this example in the interactive library

Source code

import { channel, subscribe, unsubscribe } from "node:diagnostics_channel";
const name = "helpers:sample";
const ch = channel(name);
console.log(
  (() => {
    const rows = [];
    ch.subscribe((v) => rows.push(v));
    ch.publish({ id: 7 });
    return rows;
  })(),
);

Sample output

[ { id: 7 } ]