Challenge - 5 Problems
OS Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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());
Attempts:
2 left
💡 Hint
The
os.platform() method returns a short string identifying the operating system platform.✗ Incorrect
The os.platform() method returns a string like "win32", "linux", or "darwin" to identify the OS platform in a short form.
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Check the Node.js os module docs for the return type of os.cpus().
✗ Incorrect
The os.cpus() method returns an array of objects, each describing a CPU core.
❓ component_behavior
advanced2: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?Attempts:
2 left
💡 Hint
Think about how free memory changes as programs run.
✗ Incorrect
The free memory reported by os.freemem() can change as the system allocates and frees memory.
📝 Syntax
advanced2: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.
Attempts:
2 left
💡 Hint
Node.js ES modules use import syntax with default or named imports.
✗ Incorrect
In ES modules, import * as os from 'os'; imports the os module as a namespace. Then os.totalmem() calls the function.
🔧 Debug
expert3: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());
Attempts:
2 left
💡 Hint
Check what variables are defined after import.
✗ Incorrect
The code imports only uptime but tries to call os.uptime(). The variable os is not defined, causing the error.