Skip to content

Commit 45f6470

Browse files
Merge pull request learning-zone#9 from MarcoZeee/master
Updates
2 parents 892e27c + fd6b4af commit 45f6470

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,25 @@ node app.js
207207

208208
## Q. ***Explain the concept of URL module in Node.js?***
209209

210-
*ToDo*
210+
The URL module in Node.js splits up a web address into readable parts. Use ```require()``` to include the module:
211+
212+
```javascript
213+
var url = require('url');
214+
```
215+
Then parse an address with the ```url.parse()``` method, and it will return a URL object with each part of the address as properties.
216+
217+
```javascript
218+
var url = require('url');
219+
var adr = 'http://localhost:8080/default.htm?year=2021&month=september';
220+
var q = url.parse(adr, true);
221+
222+
console.log(q.host); //returns 'localhost:8080'
223+
console.log(q.pathname); //returns '/default.htm'
224+
console.log(q.search); //returns '?year=2021&month=september'
225+
226+
var qdata = q.query; //returns an object: { year: 2021, month: 'september' }
227+
console.log(qdata.month); //returns 'september'
228+
```
211229

212230
<div align="right">
213231
<b><a href="#">↥ back to top</a></b>
@@ -338,7 +356,12 @@ Node JS Platform does not follow Request/Response Multi-Threaded Stateless Model
338356

339357
## Q. ***What are the core modules of Node.js?***
340358

341-
*ToDo*
359+
360+
They are defined within the Node.js source and are located in the lib/ folder, and Node.js has several modules compiled into the binary.
361+
362+
Core modules are always preferentially loaded if their identifier is passed to ```require()```. For instance, ```require('http')``` will always return the built in HTTP module, even if there is a file by that name.
363+
364+
Core modules can also be identified using the ```node:``` prefix, in which case it bypasses the require cache. For instance, ```require('node:http')``` will always return the built in HTTP module, even if there is ```require.cache``` entry by that name.
342365

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

0 commit comments

Comments
 (0)