[Solved] Node.js http: Parse “index of” [closed]


As suggested by rahilwazir, you can use a different URL that will give you JSON.

var request = require('request');
request( 'https://raw.githubusercontent.com/nodejs/nodejs.org/master/source/versions.json', 
       function(err, resp, json) {
          if (err) return console.error(err);
          var data = JSON.parse(json);
          // Do what you need here
       };
);

If you really want to scrape the HTML page you mentioned, you could use the following, copy pasted (and adapted) from http://maxogden.com/scraping-with-node.html

var $ = require('cheerio');

function gotHTML(err, resp, html) {
  if (err) return console.error(err);
  var parsedHTML = $.load(html);
  // get all a tags and loop over them
  var links = parsedHTML('a').map(function(i, link) {
    return $(link).attr('href');
  });
}

request('https://nodejs.org/download/release/', gotHTML);

6

solved Node.js http: Parse “index of” [closed]