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.
url module का use किसी url को readable form में split करता है , जिससे हम अपनी need के according work कर सकें।
// load url module.
const url = require('url');
const demo_url = 'http://localhost:8080/user?name=rahul&age=24&address=india';
var url_obj = url.parse(demo_url, true);
console.log('host : '+ url_obj.host);
console.log('path : '+ url_obj.pathname);
console.log('query string : ' + url_obj.search); //returns '?year=2017&month=february'
// we can also access query string as a property useing qery proprty:
var query = url_obj.query;
console.log('Name : '+ query.name);
console.log('Age : '+ query.age);
console.log('Address : '+ query.address);
C:\Users\HP\Desktop\workspace\nodejs>node app.js host : localhost:8080 path : /user query string : ?name=rahul&age=24&address=india Name : rahul Age : 24 Address : india
हालाँकि किसी भी url के बारे में completely information जानने के लिए url Object को console में print कराकर देख सकते हैं , इससे आपको हर एक property और method के बारे में पता चल जायगा।
const url = require('url');
const demo_url = 'http://localhost:8080/user?name=rahul&age=24&address=india';
var url_obj = url.parse(demo_url, true);
console.log(url_obj);
C:\Users\HP\Desktop\workspace\nodejs>node app.js Url { protocol: 'http:', slashes: true, auth: null, host: 'localhost:8080', port: '8080', hostname: 'localhost', hash: null, search: '?name=rahul&age=24&address=india', query: [Object: null prototype] { name: 'rahul', age: '24', address: 'india' }, pathname: '/user', path: '/user?name=rahul&age=24&address=india', href: 'http://localhost:8080/user?name=rahul&age=24&address=india' }