0
0
Node.jsframework~20 mins

os.platform and os.arch in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OS Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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());
A"win32"
B"windows"
C"windows_nt"
D"win64"
Attempts:
2 left
💡 Hint
Think about the exact string Node.js uses internally for Windows platform.
Predict Output
intermediate
2: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());
A"linux64"
B"x86_64"
C"amd64"
D"x64"
Attempts:
2 left
💡 Hint
Check the exact string Node.js returns for 64-bit architecture.
component_behavior
advanced
2: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()}`);
A"windows-x86"
B"win32-x86"
C"win32-ia32"
D"win32-x64"
Attempts:
2 left
💡 Hint
Remember the exact architecture string for 32-bit Windows in Node.js.
📝 Syntax
advanced
2: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?
A
import os from 'os';
console.log(os.platform(), os.arch());
B
const os = require('os');
console.log(os.platform(), os.arch());
C
import { platform, arch } from 'os';
console.log(platform(), arch());
D
import * as os from 'os';
console.log(os.platform(), os.arch());
Attempts:
2 left
💡 Hint
Consider ES module syntax and how the os module exports functions. Both default and namespace imports work for CommonJS modules.
Predict Output
expert
2: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);
A"[Function: arch]"
BTypeError: os.arch is not a function
CSyntaxError: Unexpected token import
DReferenceError: os is not defined
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.