Examples

Page 13 of 50

Browse code examples

javascriptSnippet

Async Iteration Over Emitter Events

events.on exposes an EventEmitter as an async iterable; when the passed AbortSignal fires the loop raises AbortError, so consumers can bound how much they read.

javascriptSnippet

forEach Ignores Async Callbacks

forEach calls async callbacks without awaiting them, so the loop ends before the work does; for...of awaits sequentially and Promise.all waits in parallel.

javascriptSnippet

isTTY Gates Terminal Styling

Checking process.stdout.isTTY before styling keeps piped and redirected output clean, which is what every CLI does before it emits ANSI colors.

javascriptSnippet

OS Host Machine Facts Report

os.hostname, freemem, totalmem, uptime, loadavg, and availableParallelism read the running machine, with loadavg documented as zero on Windows.

pythonSnippet

sys.exit Sets Process Exit Codes

Return codes travel through sys.exit: usage errors conventionally return 2, validation failures 1, and the value handed to sys.exit becomes the process status.