-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (38 loc) · 1.11 KB
/
app.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
var https = require("https");
var cheerio = require("cheerio");
var baseUrl = "https://nodejs.org";
var currentVersion = '';
var currentVersionRegex = /Current\sVersion\:\s/;
// Utility function that downloads a URL and invokes
// callback with the data.
function download(url, callback) {
https.get(url, function(res) {
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on("end", function() {
callback(data, undefined);
});
}).on("error", function(e) {
callback(undefined, e);
});
}
download(baseUrl, function(data, error) {
if (data) {
//console.log(data);
var $ = cheerio.load(data);
// select html node with version information
$("#intro > p").each(function(i, e) {
if (i === 1) {
currentVersion = $(e).html();
// remove 'Current Version:' from string
currentVersion = currentVersion.replace(currentVersionRegex, '');
// outputs current version available
console.log(currentVersion);
}
});
} else if (error !== undefined) {
console.log("error", error);
}
});