If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
util NodeJS में predefined / core util है इसे use करने के लिए install करने की जरूरत नहीं है। यह module में हमें file and directories के साथ work करने के लिए utilities provide करता है।
Note* अलग - अलग Operating system के according path module अलग - अलग output generate कर सकता है। By Default path module windows operating system के according work करता है।
path.basename() method किसी path का last portion return करता है।
Arguments : path : string ext : string (optional file extension.) returns : string
const path = require('path');
console.log(path.basename('C:\\Users\\HP\\Desktop\\workspace\\nodejs\\app.js'));
//Output : app.js
path.dirname() method किसी file या directory किस directory में है वो directory path return करता है।
const path = require('path');
console.log(path.dirname('C:\\Users\\HP\\Desktop\\workspace\\nodejs\\app.js'));
console.log(path.dirname('C:\\Users\\HP\\Desktop\\workspace\\nodejs'));
//Output :
C:\Users\HP\Desktop\workspace\nodejs
C:\Users\HP\Desktop\workspace
NodeJS path module का parse function किसी path को Object में parse करता है , जिसमे कि नीचे दी गयी properties होती है।
const path = require('path');
let test_path = '/images/learnhindituts_admin.jpg';
console.log(path.parse(test_path));
C:\Users\HP\Desktop\workspace\nodejs>node app.js { root: '/', dir: '/images', base: 'learnhindituts_admin.jpg', ext: '.jpg', name: 'learnhindituts_admin' }
extname() function pass किये गए किसी file path का extension return करता है।
require('path').extname('/test/something') //Outout : '' require('path').extname('/test/other/file.txt') //Output : '.txt'
resolve()function किसी file का absolute current path return करता है।
require('path').resolve('app.js'); //Output : C:\Users\HP\Desktop\workspace\nodejs\app.js
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook