Concept Flow - os module for system information
Import os module
Call os.method()
Retrieve system info
Return info to program
Display or use info
The program imports the os module, calls a method to get system info, then receives and uses that info.
import os from 'node:os'; const platform = os.platform(); console.log(platform); const cpus = os.cpus(); const cpuCount = cpus.length; console.log(cpuCount);
| Step | Action | Method Called | Returned Value | Output |
|---|---|---|---|---|
| 1 | Import os module | N/A | os module object loaded | No output |
| 2 | Call os.platform() | os.platform() | e.g. 'linux' | 'linux' printed |
| 3 | Call os.cpus() | os.cpus() | Array of CPU info objects | No output |
| 4 | Access length of CPUs array | N/A | e.g. 8 | 8 printed |
| 5 | End of script | N/A | N/A | Script ends |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|
| os | undefined | os module object | os module object | os module object | os module object |
| platform | undefined | 'linux' | 'linux' | 'linux' | 'linux' |
| cpus | undefined | undefined | Array of CPU info objects | Array of CPU info objects | Array of CPU info objects |
| cpuCount | undefined | undefined | undefined | 8 | 8 |
os module provides system info functions Import with: import os from 'node:os'; Use os.platform() to get OS name Use os.cpus() to get CPU info array Access .length for CPU count Call functions with () to get values