All I want is to log my req/res object to a file(so i can refer to it later for any object values) on redirecting to a particular page.
I tried this:
app.get("/route", function(req, res) {
res.render("route");
fs.writeFile('./data.json', JSON.stringify(req, null, 2) , 'utf-8', function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
The above code is throwing error as so:
TypeError: Converting circular structure to JSON at Object.Stringify (native)
Is there anything I should be doing differently? Any help is appreciated. Thanks in advance.