codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🟢

Node.js

12 / 63 topics
6Node.js File System7HTTP Module8Node.js Events9Streams10Buffers11Path Module12OS Module
Tutorials/Node.js/OS Module
🟢Node.js

OS Module

Updated 2026-05-15
10 min read

OS Module

Introduction

The os module in Node.js provides a way of interacting with the operating system. It offers various methods and properties to retrieve information about the underlying operating system, such as CPU architecture, network interfaces, memory usage, and more. This tutorial will guide you through using the os module to access these details.

Concept

The os module is part of Node.js's core modules, which means it is always available without needing to install any additional packages. It provides a set of functions that allow developers to interact with the operating system in a cross-platform manner. This makes it easier to write code that can run on different operating systems like Windows, macOS, and Linux.

Examples

1. Getting the Operating System Platform

The os.platform() method returns a string identifying the operating system platform for which the Node.js binary was compiled. Possible values are 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32'.

JavaScript
1const os = require('os');
2
3console.log(os.platform());
Terminal
$ node app.js
Output
linux

2. Getting the CPU Architecture

The os.arch() method returns a string identifying the operating system CPU architecture for which the Node.js binary was compiled. Possible values are 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'.

JavaScript
1const os = require('os');
2
3console.log(os.arch());
Terminal
$ node app.js
Output
x64

3. Getting the Total System Memory

The os.totalmem() method returns the total amount of system memory in bytes as an integer.

JavaScript
1const os = require('os');
2
3console.log(os.totalmem());
Terminal
$ node app.js
Output
17179869184

4. Getting the Free System Memory

The os.freemem() method returns the amount of free system memory in bytes as an integer.

JavaScript
1const os = require('os');
2
3console.log(os.freemem());
Terminal
$ node app.js
Output
8589934592

5. Getting the Hostname

The os.hostname() method returns the hostname of the operating system as a string.

JavaScript
1const os = require('os');
2
3console.log(os.hostname());
Terminal
$ node app.js
Output
my-hostname.local

6. Getting Network Interfaces

The os.networkInterfaces() method returns an object containing network interfaces that have been assigned a network address.

JavaScript
1const os = require('os');
2
3console.log(os.networkInterfaces());
Terminal
$ node app.js
Output
{
lo0: [
  {
    address: '127.0.0.1',
    netmask: '255.0.0.0',
    family: 'IPv4',
    mac: '00:00:00:00:00:00',
    internal: true,
    cidr: '127.0.0.1/8'
  }
],
en0: [
  {
    address: '192.168.1.100',
    netmask: '255.255.255.0',
    family: 'IPv4',
    mac: 'a0:b3:c3:d4:e5:f6',
    internal: false,
    cidr: '192.168.1.100/24'
  }
]
}

What's Next?

In the next section, we will explore how to manage child processes in Node.js using the child_process module.

Info

Remember, the os module is a powerful tool for accessing system-level information. It can be particularly useful for applications that need to adapt their behavior based on the underlying operating system.


PreviousPath ModuleNext Child Processes

Recommended Gear

Path ModuleChild Processes