0
0
Node.jsframework~5 mins

os.platform and os.arch in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does os.platform() return in Node.js?

os.platform() returns a string identifying the operating system platform on which the Node.js process is running, such as 'win32', 'linux', or 'darwin'.

Click to reveal answer
beginner
What information does os.arch() provide in Node.js?

os.arch() returns a string that describes the CPU architecture of the Node.js process, like 'x64', 'arm', or 'ia32'.

Click to reveal answer
intermediate
Why is it useful to know the platform and architecture in a Node.js app?

Knowing the platform and architecture helps your app run the right code or load the correct files for the user's system, like choosing compatible binaries or handling OS-specific features.

Click to reveal answer
beginner
Example: What will console.log(os.platform()) output on a Mac computer?

It will output 'darwin', which is the platform name Node.js uses for macOS.

Click to reveal answer
intermediate
How can you use os.arch() to check if your Node.js app is running on a 64-bit system?

You can check if os.arch() returns 'x64', which means the system is 64-bit.

Click to reveal answer
What does os.platform() return in Node.js?
AThe current working directory
BThe operating system platform name
CThe Node.js version
DThe CPU architecture
Which of these is a possible output of os.arch()?
Ax64
Blinux
Cdarwin
Dnode
If os.platform() returns 'win32', what does it mean?
AThe app runs on macOS
BThe app runs on Linux OS
CThe app runs on Windows OS
DThe app runs on Android
Why might a Node.js app check os.arch()?
ATo decide which CPU-specific code or binaries to use
BTo get the user's IP address
CTo find the Node.js version
DTo read environment variables
Which Node.js module provides platform() and arch() methods?
Afs
Bpath
Chttp
Dos
Explain what os.platform() and os.arch() do in Node.js and why they are useful.
Think about how your app might behave differently on Windows vs Mac or 32-bit vs 64-bit.
You got /4 concepts.
    Describe a scenario where checking os.arch() would help your Node.js application.
    Imagine your app needs to run a native addon or external program.
    You got /3 concepts.