Challenge - 5 Problems
OS Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of os.platform() on Windows
What will be the output of the following Node.js code snippet when run on a Windows machine?
Node.js
import os from 'os'; console.log(os.platform());
Attempts:
2 left
💡 Hint
Think about the exact string Node.js uses internally for Windows platform.
✗ Incorrect
Node.js returns "win32" for Windows platforms regardless of 32-bit or 64-bit architecture.
❓ Predict Output
intermediate2:00remaining
Output of os.arch() on 64-bit Linux
What will be the output of this Node.js code on a 64-bit Linux system?
Node.js
import os from 'os'; console.log(os.arch());
Attempts:
2 left
💡 Hint
Check the exact string Node.js returns for 64-bit architecture.
✗ Incorrect
Node.js returns "x64" for 64-bit architectures in os.arch().
❓ component_behavior
advanced2:00remaining
Behavior of os.platform() and os.arch() in cross-platform script
Consider a Node.js script that logs os.platform() and os.arch(). What will be the output if the script runs on a 32-bit Windows machine?
Node.js
import os from 'os'; console.log(`${os.platform()}-${os.arch()}`);
Attempts:
2 left
💡 Hint
Remember the exact architecture string for 32-bit Windows in Node.js.
✗ Incorrect
On 32-bit Windows, os.platform() returns "win32" and os.arch() returns "ia32".
📝 Syntax
advanced2:00remaining
Correct import and usage of os module for platform and arch
Which of the following code snippets correctly imports the os module and logs platform and architecture in Node.js ES modules?
Attempts:
2 left
💡 Hint
Consider ES module syntax and how the os module exports functions. Both default and namespace imports work for CommonJS modules.
✗ Incorrect
In ES modules, Node.js supports default import import os from 'os'; and namespace import import * as os from 'os'; for CommonJS modules like 'os', allowing access to os.platform() and os.arch(). Option B uses CommonJS require. Option C fails because the os module does not provide named exports for platform and arch.
❓ Predict Output
expert2:00remaining
Output when accessing os.arch without calling it
What will be the output of this code when run in a Node.js ES modules environment?
Node.js
import os from 'os'; console.log(os.arch);
Attempts:
2 left
💡 Hint
Check if os.arch is called as a function or accessed as a property. Without parentheses, it references the function itself.
✗ Incorrect
No error is produced. os.arch is a function, so console.log(os.arch) without parentheses logs the function object, which Node.js console displays as [Function: arch].