0
0
Node.jsframework~10 mins

os.platform and os.arch in Node.js - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - os.platform and os.arch
Start
Call os.platform()
Return platform string
Call os.arch()
Return architecture string
Use or display values
End
The program calls os.platform() to get the OS type, then os.arch() to get CPU architecture, then uses these values.
Execution Sample
Node.js
import os from 'node:os';

const platform = os.platform();
console.log(platform);

const arch = os.arch();
console.log(arch);
This code prints the current operating system platform and CPU architecture.
Execution Table
StepActionFunction CallReturned ValueOutput
1Start program---
2Call os.platform()os.platform()"win32" (example)Prints "win32"
3Call os.arch()os.arch()"x64" (example)Prints "x64"
4End program---
💡 Program ends after printing platform and architecture strings.
Variable Tracker
VariableStartAfter os.platform()After os.arch()Final
platformundefined"win32""win32""win32"
archundefinedundefined"x64""x64"
Key Moments - 2 Insights
Why does os.platform() return strings like "win32" even on 64-bit Windows?
os.platform() returns a fixed string identifying the OS family, not the bitness. See execution_table step 2 where "win32" is returned regardless of 64-bit CPU.
Is os.arch() the same as the OS bit version?
No, os.arch() returns the CPU architecture Node.js runs on, e.g., "x64" or "arm64". This is shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what does os.platform() return at step 2?
A"linux"
B"win32"
C"x64"
D"arm64"
💡 Hint
Check the Returned Value column at step 2 in execution_table.
At which step does the program print the CPU architecture?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the Output column in execution_table for when os.arch() is called.
If the CPU architecture was "arm64", how would variable_tracker change after os.arch()?
Aarch would be "x64"
Bplatform would change to "arm64"
Carch would be "arm64"
Dplatform would be undefined
💡 Hint
See variable_tracker row for arch after os.arch() call.
Concept Snapshot
os.platform() returns a string identifying the OS platform (e.g., "win32", "linux").
os.arch() returns the CPU architecture Node.js runs on (e.g., "x64", "arm64").
Both are synchronous functions from the 'os' module.
Use them to detect environment details for your Node.js app.
Values are strings and do not reflect OS bitness exactly.
Call and use them simply like: const p = os.platform(); const a = os.arch();
Full Transcript
This example shows how Node.js uses the os module to get platform and architecture info. The program starts and calls os.platform(), which returns a string like "win32" to identify the operating system. Then it calls os.arch(), which returns the CPU architecture string like "x64". These values are printed to the console. The variable tracker shows how platform and arch variables get assigned after each call. Beginners often wonder why os.platform() returns "win32" even on 64-bit Windows; this is because it identifies the OS family, not bitness. Also, os.arch() returns the CPU architecture Node.js runs on, not the OS version. The visual quiz asks about these returned values and their timing in the execution steps. This helps learners see exactly when and what values are returned and printed.