Friday 26 July 2019

How to write to a file the whole response of a HTTP request?

Hi all,I'm trying to get the whole response of a HTTP request with the "request" module.When I write the response to the console like this:const request = require("request"); const fs = require("fs"); request("http://www.google.com", function(error, response, body) { console.log("response:", response); }); the whole response is written to the console.When I try to write it to a file like this:const request = require("request"); const fs = require("fs"); callback = function(err) { if (err) { return console.log(err); } }; request("http://www.google.com", function(error, response, body) { //console.log("response:", response); var json = JSON.stringify(response); fs.writeFile("google.json", json, "utf8", callback); }); only a small part of the response is written to the file.E.g. response._readableState, response._events and others are missing.So, how can I write it all to a file as JSON, ideally without the object types e.g. IncomingMessage?

Submitted July 26, 2019 at 07:44PM by reditoro

No comments:

Post a Comment