← Back to Node.js Course | Chapter 2: Core Modules | Lesson 3 of 7

os मॉड्यूल

os module आपको उस computer के बारे में बताता है जिस पर आपका program चल रहा है।

In this page:

  1. os Module
Syntax
javascript
const os = require('os');
os.platform()
os.cpus().length
os.totalmem()
os.homedir()

os Module

os platform, CPU architecture, CPU count, memory, home directory, temp directory, और line ending expose करता है। यह cross-platform tools और diagnostics लिखने के लिए useful है।

Note: text files लिखते वक्त line endings के लिए os.EOL इस्तेमाल करें।

उदाहरण: os module

javascript
const os = require("os");
console.log("platform is string:", typeof os.platform());
console.log("cpus > 0:", os.cpus().length > 0);
console.log("total >= free memory:", os.totalmem() >= os.freemem());
console.log("EOL is newline:", os.EOL === "\n" || os.EOL === "\r\n");

// Output:
// platform is string: string
// cpus > 0: true
// total >= free memory: true
// EOL is newline: true

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि platform Linux है
  2. os.tmpdir() की बजाय /tmp hard-code करना
  3. total और free memory को confuse करना
चैप्टर सारांश
  • os host machine describe करता है
  • platform() और arch() system identify करते हैं
  • tmpdir() और homedir() paths देते हैं
  • EOL line ending है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.