forked from MartinChavez/Node.js-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08 - Module Loader.js
More file actions
28 lines (20 loc) · 938 Bytes
/
08 - Module Loader.js
File metadata and controls
28 lines (20 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Load the custom module using 'require'
var moduleFunction = require('./7 - modules');
// It is possible to use all of the export methods from the custom Module
moduleFunction();
// When you require a module using './', it is going to look in the same directory
// as the application, for a file with that name
var makeRequest = require('./9 - http module');
makeRequest('http req 1');
makeRequest('http req 2');
// When you use '../', it is going to look in the parent directory
// When you don't specify any directory, it is going to search in node_modules directory (inside the current app)
// When 'require' doesn't find the module in the current app, it is going to search
// in node_modules directory (Home directory)
/*
Run the following cmd to start node and load the custom module
node '.\08 - Module Loader.js'
Expected response:
- "Module loaded" from '7 - Modules'
- Two HTTP requests from '9 - Http Module'
*/