title: Node.js | Express.js | Redis.io - Processing order
body: <p>For my projekt I'am using Node.js with express.js and redis.io as database. Now I have a get resource with query parameter. It should give me the IDs of libraries that hold a particular book. But I dont understand the processing order of my program. As you can see in the code below I print the libraries Array 3 times to the console. </p>
  
  <pre><code>var express = require('express');
  var bodyParser = require('body-parser');
  var redis = require('redis');
  
  var db = redis.createClient();
  var jsonParser = bodyParser.json();
  var app = express();
  app.use(jsonParser);
  
  app.get('/test', function (req, res) {
  
      if (req.query.book != null) {
  
          var book_id = req.query.book;
          var libraries = [];
  
          db.get('book:' + book_id, function (err, rep) {
  
              var book = JSON.parse(rep);
              var libs = book.libraries;
  
              libs.forEach(function (val) {
  
                  libraries.push(val.id);
  
              });
              console.log("1.: " + libraries);
          });
          console.log("2.: " + libraries);
      }
      console.log("3.: " + libraries);
  });
  app.listen(1337);
  </code></pre>
  
  <p>And this is the result in my console:</p>
  
  <p>2.:</p>
  
  <p>3.:</p>
  
  <p>1.: 1,4</p>
  
  <p>Can someone explain that? And why my array is emtpy on point 2 and 3?</p>