0
0
Node.jsframework~20 mins

os module for system information 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
What is the output of this code using os module?
Consider this Node.js code snippet using the os module. What will be the output of the os.platform() call?
Node.js
import os from 'os';
console.log(os.platform());
A"win32" (on Windows), "linux" (on Linux), or "darwin" (on macOS) depending on the OS
B"Windows", "Linux", or "MacOS" as full names
CThe CPU architecture like "x64" or "arm"
DThe hostname of the computer
Attempts:
2 left
💡 Hint
The os.platform() method returns a short string identifying the operating system platform.
Predict Output
intermediate
2:00remaining
What does os.cpus() return?
Given this code snippet, what is the type of the value returned by os.cpus()?
Node.js
import os from 'os';
const cpus = os.cpus();
console.log(typeof cpus);
A"number" representing the count of CPUs
B"string" describing the CPU model
C"object" because it returns an array of CPU info objects
D"undefined" because os.cpus() does not exist
Attempts:
2 left
💡 Hint
Check the Node.js os module docs for the return type of os.cpus().
component_behavior
advanced
2:00remaining
How does os.freemem() behave in a running Node.js app?
If you call os.freemem() multiple times in a Node.js app, what can you expect about the values returned?
AThe values always return zero
BThe values remain constant during the app lifetime
CThe values increase steadily as the app runs
DThe values may change over time as memory usage changes
Attempts:
2 left
💡 Hint
Think about how free memory changes as programs run.
📝 Syntax
advanced
2:00remaining
Which option correctly imports and uses os.totalmem() in Node.js ES modules?
Choose the correct code snippet to import the os module and log total system memory in bytes.
A
import * as os from 'os';
console.log(os.totalmem());
B
const os = require('os');
console.log(os.totalmem());
C
import { totalmem } from 'os';
console.log(totalmem());
D
import os from 'os';
console.log(os.totalmem());
Attempts:
2 left
💡 Hint
Node.js ES modules use import syntax with default or named imports.
🔧 Debug
expert
3:00remaining
Why does this code throw TypeError: os.uptime is not a function?
Given this code snippet, why does it throw a TypeError?
Node.js
import { uptime } from 'os';
console.log(os.uptime());
ABecause uptime is not a function in the os module
BBecause os is not defined; only uptime was imported, so os.uptime() is undefined
CBecause import syntax is invalid for os module
DBecause uptime requires arguments but none were given
Attempts:
2 left
💡 Hint
Check what variables are defined after import.