Monday, 3 April 2017

How to save the contents obtained by request in a variable

I want to assign the content of the site acquired by specifying by URL to a variable.

Source

request-sample.js

var request = require('request');

var html = '';

request('https://www.google.com', function(error, response, body) {
  html = body;
});

// Below, proceed with processing using saved contents
console.log(html);

Result

$ node request-sample.js
$
(Nothing is output...)

How can I solve it?



via ina6ra

No comments:

Post a Comment