# Node.js URL Module

In 
Published 2022-12-03

The URL module in Node.js splits up (parse) a web address into readable parts, and you can do a lot of interesting things after that. You can redirect the request or create the response based of the page parameters you receive.

In order to use the URL module in Node.js you have to import the module into the application using the require() method.

Here it is an example of using URL module in Node.js:

var url = require('url');
 
var adrURL = 'http://localhost:80/index.html?name=John&id=3433';
var var1 = url.parse(adrURL, true);
console.log(' ');
console.log(var1.host); 
console.log(var1.pathname); 
console.log(var1.search); 
 
console.log(' ');
var var2 = var1.query; 
console.log(var2.name);
console.log(var2.id);
console.log(' ');
console.log('END of Node.js application.');

... and here it is the execution on the console: