Built-in Modules
A built-in module ships with Node.js. Built-in means it arrives with Node.js, so no install is needed.
Load the os module
This line loads the built-in os module.
const os = require("os");Name the platform
This line prints the name of this operating system.
console.log(os.platform());Example
const os = require("os");
console.log(os.platform());
console.log(os.arch());Key points
- A built-in module is part of Node.js itself.
- Load a built-in module by its short name.
- require("os") loads the module about the operating system.
- An operating system runs the computer and its programs.
- os is short for operating system.
- os.platform() names the operating system of the computer.
In this example, the opening line loads the built-in os module. The second line prints the operating system name. This machine prints linux. The third line prints the processor type. This machine prints x64.
Note
The answer names this machine, so another computer prints its own name.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
How do you load a built-in module?