path मॉड्यूल
path module हर operating system पर सही तरीके से file paths बनाता और तोड़ता है।
In this page:
Syntax
const path = require('path');
path.join(segment1, segment2)
path.resolve(segment)
path.basename(filePath)
path.extname(filePath)
path Module
path.join सही separator से segments जोड़ता है, path.resolve एक absolute path बनाता है, और path.basename, dirname, और extname paths अलग करते हैं। path इस्तेमाल करना slashes वाली hand-built strings से आने वाली bugs से बचाता है।
Note:
अपने script के बगल की files reference करने के लिए path.join(__dirname, "file") इस्तेमाल करें।
उदाहरण: path module
const path = require("path");
console.log(path.join("a", "b", "..", "c.txt"));
console.log(path.basename("/tmp/app/index.js"));
console.log(path.extname("photo.final.png"));
console.log(path.dirname("/tmp/app/index.js"));
console.log(path.parse("/home/u/file.txt").name);
// Output:
// a/c.txt
// index.js
// .png
// /tmp/app
// file
⚠️ 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. #}
आम गलतियां
- plus signs से paths concatenate करना
- backslashes hard-code करना
- join को resolve से confuse करना
चैप्टर सारांश
- join segments combine करता है
- resolve absolute paths बनाता है
- basename, dirname, extname paths split करते हैं
- Operating systems के आर-पार काम करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: