OS and util helpers
Local practice: Node.js 22.16.0 and npm 10.9.2 on Linux x64; proposed teaching baseline 26.13.1 LTS remains untested. Use a fresh disposable folder for each example, copy only the shown files and run the fixed command. No packages or external services required. Static examples are not ByteMind runner support. The archive is author-only; do not copy expected.json into the example directory.
Inspect platform conventions without host identifiers
import os from "node:os";console.log(typeof os.platform());console.log(["\n", "\r\n"].includes(os.EOL));console.log(Number.isInteger(os.availableParallelism()) && os.availableParallelism() >= 1);Run in this fixture directory:
node main.mjsExpected stdout:
stringtruetrueExpected exit status: 0. Expected stderr: empty. The assertions check the expected kinds of values without recording the host platform string or core count.
How it works
os.platform() and os.arch() report the runtime platform and architecture; os.EOL is the platform newline, whereas protocol formats may require a fixed newline. os.availableParallelism() estimates available parallel execution capacity; it is not a guaranteed best worker count. util.format() creates formatted strings and util.inspect() produces debugging-oriented representations rather than a stable serialization format. util.types offers runtime predicates, including isDate. The examples avoid printing unique system identifiers. Use JSON with a documented schema for data interchange.
Format a known diagnostic
import { format, inspect, types } from "node:util";console.log(format("Catalog %s: %d items", "demo", 4));console.log(inspect({ ready: true }, { colors: false }));console.log(types.isDate(new Date(0)), types.isDate("1970-01-01"));Run in this fixture directory:
node main.mjsExpected stdout:
Catalog demo: 4 items{ ready: true }true falseExpected exit status: 0. Expected stderr: empty. Formatting produces a string; the predicate distinguishes a Date object from text. The exact inspect spelling is tested only on the local version.
Common mistake
Do not use inspect output as a stable machine-readable contract or dump a large object containing secrets. A platform check does not establish that a specific optional capability is installed.
Try it yourself
Create a diagnostic string from a known synthetic report object. Compare JSON serialization with inspect output, and explain which you would send to a JSON API.
Further reading: Official documentation 1, Official documentation 2. Related ByteMind reference candidate: node-util-format (route not verified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
OS and util helpers — knowledge check
Apply the concepts and predict the behavior taught in this lesson.
Which helper estimates available parallel execution capacity?
Which format should be used for a documented JSON interface?
Which helper distinguishes a Date instance from a date string?