Q:

fs.appendFile returning [object Object]

console.log is returning req.query (request.query) correctly, as { name: 'sean', comments: 'Hey' }. But when I try to write it to a file using fs.appendFile, it is writing it as [object Object]. Here's the server code: 
  app.get('/', function (req, res) {
var rq = req.query  //Write req.query to a variable
console.log("received: ", rq)   //This returns correctly
fs.appendFile('comments.txt', rq, function (req, err) {  //This is where object Object is written
if (err) throw err;
console.log("written: ", rq)  //This returns correctly
});
  res.header('Content-type', 'text/html');
  return res.end('<h1>Hello, World!</h1>');
});

Any thoughts? Thanks.

A:

You need to serialize Javascript objects to string before you can write them to a file properly. One way to do that is to use JSON.stringify():
fs.appendFile('comments.txt', JSON.stringify(rq), function(err) {
  ...
});

(the callback to fs.appendFile() only receives one argument, err, AFAIK)

