Skip to content

Commit fd6b4af

Browse files
authored
Update README.md
1 parent 0256ebe commit fd6b4af

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,25 @@ node app.js
192192

193193
## Q. ***Explain the concept of URL module in Node.js?***
194194

195-
*ToDo*
195+
The URL module in Node.js splits up a web address into readable parts. Use ```require()``` to include the module:
196+
197+
```javascript
198+
var url = require('url');
199+
```
200+
Then parse an address with the ```url.parse()``` method, and it will return a URL object with each part of the address as properties.
201+
202+
```javascript
203+
var url = require('url');
204+
var adr = 'http://localhost:8080/default.htm?year=2021&month=september';
205+
var q = url.parse(adr, true);
206+
207+
console.log(q.host); //returns 'localhost:8080'
208+
console.log(q.pathname); //returns '/default.htm'
209+
console.log(q.search); //returns '?year=2021&month=september'
210+
211+
var qdata = q.query; //returns an object: { year: 2021, month: 'september' }
212+
console.log(qdata.month); //returns 'september'
213+
```
196214

197215
<div align="right">
198216
<b><a href="#">↥ back to top</a></b>

0 commit comments

Comments
 (0)