title: NodeJS: How to use async.js to process a list of items in database
body: <p>I have this problem: I get a list of items from an API and I have to save them in database. For each of them I have to display some feedback, like " - item name. Saving in DB.." and after saving it show something like "Sucess! Next...".</p>
  
  <p>I'm using async link to iterate through the items in the array and save in DB. The problem is that the messages don't sync. It shows a bunch of the item name message and after a bunch of the success message. My code below.</p>
  
  <pre><code>var saveInDB = function saveInDB(item, callback) {
  
      console.log(' - ' + item.market_name + ' .......');
  
      // Simulating some delay
      setTimeout(function () {
          console.log('Success! Next....');
          callback(null);
      }, 3000);
  }
  
  
  util.getJsonFromUrl(API_URL, function (err, data) {
  
      if (err || !data || !data.results || data.results.length == 0)
      {
          console.log('BAD');
      }
      else
      {
          console.log('Items downloaded...');
  
          async.each(
              data.results,
              function (item, callback) {
  
                  saveInDB(item, callback);
  
              },
              function (err) {
                  if (err) {
                      console.log('ERROR');
                  }
                  else {
                      console.log('Success!');
                  }
              }
          );
      }
  });
  </code></pre>
  
  <p>Yes, I have tried to use .series but I just cant get it to work. I was looking for examples and I still don't get how to simply pass the item as in .each.</p>
  
  <p>Can you help me? Thanks in advance for any help.</p>