Working with OS Module
1. Getting OS Platform (os.platform)
| Value | Meaning |
|---|---|
"darwin" | macOS |
"linux" | Linux |
"win32" | Windows (32 + 64-bit) |
"freebsd" / "aix" / "sunos" | Other UNIX |
2. Getting OS Architecture (os.arch)
| Value | Meaning |
|---|---|
x64 | 64-bit Intel/AMD |
arm64 | Apple Silicon, ARM64 |
ia32 | 32-bit x86 |
3. Getting OS Type (os.type)
| Returns | Example |
|---|---|
os.type() | Linux, Darwin, Windows_NT |
os.version() | Kernel/build version |
os.release() | Release string |
4. Getting Hostname (os.hostname)
| API | Returns |
|---|---|
os.hostname() | Machine hostname |
5. Getting Home Directory (os.homedir)
| API | Returns |
|---|---|
os.homedir() | e.g. /Users/alice or C:\Users\alice |
6. Getting Temp Directory (os.tmpdir)
| API | Returns |
|---|---|
os.tmpdir() | e.g. /tmp |
7. Getting User Info (os.userInfo)
| Field | Description |
|---|---|
username | Login name |
uid / gid | User/group IDs (POSIX) |
shell | Default shell |
homedir | Home directory |
8. Getting CPU Info (os.cpus)
Example
import os from "node:os";
console.log(os.cpus().length, "cores");
console.log(os.availableParallelism()); // preferred for sizing pools (v18.14+)
| API | Use |
|---|---|
os.cpus() | Per-core model + times |
os.availableParallelism() | Honors cgroup/affinity limits v18.14+ |
9. Getting Total Memory (os.totalmem)
| API | Returns |
|---|---|
os.totalmem() | Total bytes |
10. Getting Free Memory (os.freemem)
| API | Returns |
|---|---|
os.freemem() | Free bytes |
11. Getting System Uptime (os.uptime)
| API | Returns |
|---|---|
os.uptime() | Seconds since boot |
process.uptime() | Seconds since process start |
12. Getting Network Interfaces (os.networkInterfaces)
| Field | Detail |
|---|---|
address | IP |
family | IPv4 / IPv6 |
internal | Loopback flag |
mac | MAC address |
13. Getting EOL Character (os.EOL)
| OS | Value |
|---|---|
| POSIX | \n |
| Windows | \r\n |