os.hostname()
Returns the host name of the operating system.
Syntax
os.hostname() Returns
string — The machine host name.
Examples
import { hostname } from 'node:os';
console.log(hostname());
Output
macbook-pro.local
import { hostname } from 'node:os';
console.log(`[${hostname()}] worker started`);
Output
[web-01] worker started
Notes
Useful for tagging log lines or metrics with the machine name in
multi-instance deployments. In containers this is usually the
container ID unless overridden.