File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -192,7 +192,25 @@ node app.js
192
192
193
193
## Q. *** Explain the concept of URL module in Node.js?***
194
194
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
+ ```
196
214
197
215
<div align =" right " >
198
216
<b><a href="#">↥ back to top</a></b>
You can’t perform that action at this time.
0 commit comments