NodeJS os Module


NodeJS modules की list में अगला important module है os . os module कई ऐसे functions provide करता है , जिनका use system की information get करने के लिए किया जाता है।


os module को print कराकर आप सभी useful functions और properties के बारे में जान सकते हैं।बाकी कुछ useful functions examples के साथ नीचे दिखाए गए हैं।

os.arch()

यह function machine का architecture like arm, x64, arm64 के बारे में बताता है।

console.log(require('os').arch());
//Output : x64

os.type()

यह operating system का type return करता है।

console.log(require('os').type());
//Output : Windows_NT

os.cpus()

यह function आपके machine में available CPUs के बारे में बताता है।

Copy Fullscreen Close FullscreenRun
console.log(require('os').arch());
C:\Users\HP\Desktop\workspace\nodejs>node app.js
[
  {
    model: 'Intel(R) Core(TM) i5-3340M CPU @ 2.70GHz',
    speed: 2691,
    times: {
      user: 1305953,
      nice: 0,
      sys: 1306750,
      idle: 25623828,
      irq: 181046
    }
  },
  {
    model: 'Intel(R) Core(TM) i5-3340M CPU @ 2.70GHz',
    speed: 2691,
    times: { user: 1097953, nice: 0, sys: 650656, idle: 26487734, irq: 12421 }
  },
  {
    model: 'Intel(R) Core(TM) i5-3340M CPU @ 2.70GHz',
    speed: 2691,
    times: { user: 1349578, nice: 0, sys: 952781, idle: 25933984, irq: 20343 }
  },
  {
    model: 'Intel(R) Core(TM) i5-3340M CPU @ 2.70GHz',
    speed: 2691,
    times: { user: 1210218, nice: 0, sys: 653687, idle: 26372453, irq: 8062 }
  }
]

os.freemem()

यह function आपके system में available free memory को bytes में बताता है।

console.log(require('os').freemem());
//Output : 647602176

os.totalmem()

यह function आपके system में available total memory को bytes में बताता है।

console.log(require('os').totalmem());
//Output : 4193673216

os.networkInterfaces()

यह function आपके system पर available सभी network interfaces की details बताता है।

Copy Fullscreen Close FullscreenRun
console.log(require('os').networkInterfaces());
C:\Users\HP\Desktop\workspace\nodejs>node app.js
{
  'Wi-Fi 2': [
    {
      address: '2409:4052:e08:bf88:4941:c502:32a2:8444',
      netmask: 'ffff:ffff:ffff:ffff::',
      family: 'IPv6',
      mac: 'e0:9d:31:2a:ca:20',
      internal: false,
      cidr: '2409:4052:e08:bf88:4941:c502:32a2:8444/64',
      scopeid: 0
    },
    {
      address: '2409:4052:e08:bf88:38be:8e61:ea3b:1cad',
      netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      family: 'IPv6',
      mac: 'e0:9d:31:2a:ca:20',
      internal: false,
      cidr: '2409:4052:e08:bf88:38be:8e61:ea3b:1cad/128',
      scopeid: 0
    },
    {
      address: 'fe80::4941:c502:32a2:8444',
      netmask: 'ffff:ffff:ffff:ffff::',
      family: 'IPv6',
      mac: 'e0:9d:31:2a:ca:20',
      internal: false,
      cidr: 'fe80::4941:c502:32a2:8444/64',
      scopeid: 3
    },
    {
      address: '192.168.246.194',
      netmask: '255.255.255.0',
      family: 'IPv4',
      mac: 'e0:9d:31:2a:ca:20',
      internal: false,
      cidr: '192.168.246.194/24'
    }
  ],
  'Loopback Pseudo-Interface 1': [
    {
      address: '::1',
      netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      family: 'IPv6',
      mac: '00:00:00:00:00:00',
      internal: true,
      cidr: '::1/128',
      scopeid: 0
    },
    {
      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'
    }
  ]
}

os.release()

यह operating system का release number string करता है।

console.log(require('os').release());
//Output : 10.0.19042

os.userInfo()

यह current user के info return करता है।

console.log(require('os').userInfo());

//Output : 
{
  uid: -1,
  gid: -1,
  username: 'HP',
  homedir: 'C:\\Users\\HP',
  shell: null
}

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook