title: Write objects into file with Node.js
body: <p>I've searched all over stackoverflow / google for this, but can't seem to figure it out. </p>
  
  <p>I'm scraping social media links of a given URL page, and the function returns an object with a list of URLs. </p>
  
  <p>When I try to write this data into a different file, it outputs to the file as <code>[object Object]</code> instead of the expected: 
      [ '<a href="https://twitter.com/#!/101Cookbooks" rel="noreferrer">https://twitter.com/#!/101Cookbooks</a>',
      '<a href="http://www.facebook.com/101cookbooks" rel="noreferrer">http://www.facebook.com/101cookbooks</a>'] 
  as it does when I <code>console.log()</code> the results.</p>
  
  <p>This is my sad attempt to read and write a file in Node, trying to read each line(the url) and input through a function call <code>request(line, gotHTML)</code>: </p>
  
  <pre><code>fs.readFileSync('./urls.txt').toString().split('\n').forEach(function (line){
      console.log(line); 
      var obj = request(line, gotHTML); 
      console.log(obj); 
      fs.writeFileSync('./data.json', obj , 'utf-8'); 
  });   
  </code></pre>
  
  <p>for reference -- the <code>gotHTML</code> function: </p>
  
  <pre><code>function gotHTML(err, resp, html){ 
      var social_ids = []; 
  
      if(err){
          return console.log(err); 
      } else if (resp.statusCode === 200){ 
          var parsedHTML = $.load(html); 
  
          parsedHTML('a').map(function(i, link){
              var href = $(link).attr('href');
              for(var i=0; i&lt;socialurls.length; i++){
                  if(socialurls[i].test(href) &amp;&amp; social_ids.indexOf(href) &lt; 0 ) {
                      social_ids.push(href); 
                  }; 
              }; 
          })
      };
  
      return social_ids;
  };
  </code></pre>