SkillByAIइंटरैक्टिव संस्करण खोलें →

पाठ 11 / 30

path मॉड्यूल

path module से cross-platform file paths बनाएँ और ES modules में __dirname का विकल्प उपयोग करें।

पथ जोड़ना

path.join वर्तमान OS के लिए सही सेपरेटर उपयोग करता है।

import path from "node:path";

const filePath = path.join("data", "users", "list.json");
console.log(filePath);                // data/users/list.json
console.log(path.basename(filePath)); // list.json
console.log(path.extname(filePath));  // .json

ESM में __dirname

ES modules में __dirname नहीं होता — इसे import.meta.url से fileURLToPath द्वारा निकालें।