os मॉड्यूल
os module आपको उस computer के बारे में बताता है जिस पर आपका program चल रहा है।
In this page:
Syntax
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
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. #}
आम गलतियां
- यह मान लेना कि platform Linux है
- os.tmpdir() की बजाय /tmp hard-code करना
- 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: