-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
49 lines (36 loc) · 946 Bytes
/
map.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// The magical module
var http = require('http');
// The useful module
var asynchronous = require('async');
// Retrieve url content
var retrieve = function(item, cb) {
// Try to retrieve
http.get(item, function(response) {
// Complete response
var content = '';
// When data streams in
response.on('data', function(data) {
// Add it up
content += data.toString();
});
// When all is said and done
response.on('end', function() {
// Share result with the world
return cb(null, content);
});
}).on('error', function(error) {
console.error(error);
});
};
// To handle results
var callback = function(error, result) {
// If something went wrong
if (error) {
// Just speak it out
console.log(error);
}
// Do the same for success
console.log(result);
};
// Bring it all together
asynchronous.map([process.argv[2], process.argv[3]], retrieve, callback);