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 = '';
var u = url.parse(address, true);

console.log(; //returns ''
console.log(u.pathname); //returns '/demo.htm'
console.log(; //returns '?a=2017&b=february'

var qdata = u.query; //returns an object: { a: 2017, b: 'february' }
console.log(qdata.b); //returns 'february'

Below screenshot shows the output of this program.

url module

Subscribe Now