Nodejs URL
URL Module –
Used to parse the URL. url.parse() method is used to parse the address.
Create a js file with below code named url.js and run this application. As described it will parse the url and print the details in console.
var url = require('url'); var address = 'http://domainame.com/demo.htm?a=2017&b=february'; var u = url.parse(address, true); console.log(u.host); //returns 'domainame.com' console.log(u.pathname); //returns '/demo.htm' console.log(u.search); //returns '?a=2017&b=february' var qdata = u.query; //returns an object: { a: 2017, b: 'february' } console.log(qdata.b); //returns 'february'