In Node.js / Express, how do I “download” a page and gets its HTML?

var util = require("util"),
    http = require("http");

var options = {
    host: "www.google.com",
    port: 80,
    path: "https://stackoverflow.com/"
};

var content = "";   

var req = http.request(options, function(res) {
    res.setEncoding("utf8");
    res.on("data", function (chunk) {
        content += chunk;
    });

    res.on("end", function () {
        util.log(content);
    });
});

req.end();

Leave a Comment