1. CPU cores
os.cpus() returns one entry per logical core, so .length tells you how many cores are available.
os.cpus().lengthTyporithm · easy
Step 1 of 8 · intro card
Core Modules
node:os exposes system info: os.cpus() (cores), os.totalmem()/freemem() (RAM), os.platform(), os.hostname(), os.homedir(), and os.tmpdir(). Use it for capacity decisions like sizing a worker pool to os.cpus().length.
os.cpus() returns an array with one entry per logical core, so os.cpus().length is the standard way to count cores; os.totalmem() and os.freemem() report total and free RAM in bytes.
os.platform() returns the OS string ("darwin", "linux", "win32") for branching, os.hostname() gives the machine name, and os.homedir() and os.tmpdir() return the user's home and the OS temp directory.
The practical use is capacity planning: size a worker pool or concurrency limit to os.cpus().length, and use freemem() to back off when memory is scarce rather than hardcoding numbers per machine.
os.cpus().length counts logical cores.
os.totalmem()/freemem() report RAM in bytes.
os.platform(), hostname(), homedir(), tmpdir() give system paths and info.
import os from "node:os";
const cpuCount = os.cpus().length; // number of logical cores
const total = os.totalmem(); // bytes of RAM
const free = os.freemem(); // bytes currently free
const platform = os.platform(); // "darwin" | "linux" | "win32"
const host = os.hostname(); // machine name
const home = os.homedir(); // user home directory
const tmp = os.tmpdir(); // OS temp directory
const poolSize = os.cpus().length; // size a worker pool to the coresConnect each part of the code to the concept before you type.
os.cpus() returns one entry per logical core, so .length tells you how many cores are available.
os.cpus().lengthos.totalmem() reports total system RAM in bytes; os.freemem() reports what is currently free.
os.totalmem()os.platform() returns the OS identifier like "darwin", "linux", or "win32" for platform branching.
os.platform()os.hostname() returns the machine's network name, handy for logging which host produced a record.
os.hostname()os.tmpdir() returns the OS temp directory; os.homedir() returns the current user's home directory.
os.tmpdir()Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.