Lesson 10 of 30

OS Module

Chapter 10

OS Module

Learn how to retrieve operating system information using Node.js.

Theory

The os module provides information about the operating system. It can provide information such as: • Platform • CPU architecture • CPU information • Home directory • Hostname • Total memory • Free memory This can be useful when building system-level utilities.

Example

Node.js Example
const os = require("os");

console.log("Platform:", os.platform());
console.log("Home:", os.homedir());
console.log("Memory:", os.totalmem());

Output

Operating system information is displayed in the terminal.

Practice

Use the os module to display your system platform, hostname, and memory.

Interview Questions

1.

What is the os module?

2.

How can you get the operating system platform?

3.

How can you get the home directory?

Quick Quiz

Which option best matches this chapter?

A.os
B.fs
C.path
D.http

Answer: os