title: NodeJS synchronous functions
body: <p>I have a text file which simply lists some URL's. I'm trying to take each line from the text file, and add it to an array of urls for further operation. </p>
  
  <pre><code>var fs = require('fs'),
      Urls = [];
  
  var returnURLS = function(file) {
  
      var read = function(callback) {
          fs.readFile(file, function(err, logData){
              if (err) throw err;
              var text = logData.toString();
              var lines = text.split('\n');
              lines.forEach(function(line, callback){
                  var url = "http://www." + line;
                  Urls.push(url);
              });
              callback();
          });
      };
  
      var giveBackAnswer = function() {
          console.log("1: ", Urls);
          return Urls;     
      };
  
      read(giveBackAnswer);
  
  };
  
  console.log("2: ", returnURLS('textFileWithListOfURLs.txt'));
  </code></pre>
  
  <p>My <strong>console output</strong> clearly shows that the file system operations have not completed by the time the program is supposed to log the results, but that the results eventually do show up.</p>
  
  <pre><code>2: the urls are  undefined
  1:  [ 'http://www.cshellsmassage.com',
    'http://www.darsanamartialarts.com',
    'http://www.davidgoldbergdc.com',
    'http://www.dayspaofbroward.com',.... (etc)
  </code></pre>
  
  <p>What is the best way to get these functions to operate synchronously? 
  1) Compile the Urls array through file system operations
  2) Print the array to the console once it has been filled</p>