Skip to main content
Technology & EngineeringNodejs Patterns30 lines

Stream Job Output to a Dashboard

Stream controlled child-process output with bounded queues, replay offsets, safe text rendering, and verified terminal state.

Quick Summary8 lines
Define which backend jobs a viewer can read, which users can read them, and whether the display needs interactivity. Use separate stdout and stderr pipes for an ordinary progress dashboard. A PTY is relevant only when an approved program needs terminal behavior such as cursor control or interactive input. Keep this workflow read-only from the browser. Select commands and their argument structure in the job service. Never turn arbitrary dashboard text into a shell command.

## Key Points

- [Node.js child processes](https://nodejs.org/api/child_process.html)
- [Node.js streams](https://nodejs.org/api/stream.html)
skilldb get nodejs-patterns-skills/realtime-terminal-output-streamingFull skill: 30 lines
Paste into your CLAUDE.md or agent config

Stream Job Output to a Dashboard

Choose what the job stream represents

Define which backend jobs a viewer can read, which users can read them, and whether the display needs interactivity. Use separate stdout and stderr pipes for an ordinary progress dashboard. A PTY is relevant only when an approved program needs terminal behavior such as cursor control or interactive input. Keep this workflow read-only from the browser. Select commands and their argument structure in the job service. Never turn arbitrary dashboard text into a shell command.

For each output event record job ID, sequence number, stream, normalized text, and observed time. A single sequencer can describe observed order across both pipes, but cannot recover a stronger ordering guarantee than the child and transports provide. Decode UTF-8 with a streaming decoder so a multibyte character split across chunks remains intact. Decide how to handle carriage returns and permitted terminal control sequences. Render output as text or with a reviewed renderer that filters unsafe controls and links.

Bound memory and preserve final state

Use a bounded replay buffer keyed to each job, with explicit eviction limits and a documented oldest retained offset. If durable storage already exists, store the output under the same access and retention policy as the job. Rate-limit or disconnect a slow subscriber using the transport's backpressure signal. One browser tab should not stop the child from draining output. Batch output updates within a size and time limit so frequent writes cannot overwhelm the browser.

Capture process spawn errors, termination signal, and exit status. Finalize after the child close event when using Node's child process stream APIs, so buffered output has a chance to drain. Keep cancellation and timeout distinct from normal nonzero exit. Disallow or carefully filter secrets at the source, and treat application redaction as an extra control. Avoid exporting unrestricted process environment data.

Prove disconnect and replay behavior

Authorize each subscription against the persisted job record. Accept a last received sequence only for that job. If the cursor is still retained, replay strictly newer events and switch to live delivery without a duplicate boundary. If history was evicted, return an explicit gap and the oldest available sequence. Keep an independent final-state request so a disconnected viewer can recover success or failure.

Exercise one fixture that writes stdout and stderr, emits split Unicode, then fails. Disconnect after an intermediate sequence and verify resumed output. Test a slow consumer, evicted offset, and a second user who lacks job access. Save expected sequence ranges, final exit state, and observable denial evidence.

References

Install this skill directly: skilldb add nodejs-patterns-skills

Get CLI access →