Node.js URL Module

Node.js URL Module

URL Module is used to parse an address into host, pathname, search and query string.

parse method of URL module is used to get url properties.

Syntax :


var url = require('url');



Example :

var url = require('url');
var student = 'http://localhost:5555/getData.html?city=ahmedabad&country=india';
var data = url.parse(student, true);

console.log(; //returns 'localhost:5555'
console.log(data.pathname); //returns '/getData.html'
console.log(; //returns '?city=ahmedabad&country=india'

var objdata = data.query; //returns an object: { city: ahmedabad, country: 'india' }
console.log(; //returns 'india'





Leave a Reply

Your email address will not be published. Required fields are marked *