title: Wait for multiple events from different modules and then start the server
body: <p>I'm building an app in which I have 2 different modules.One of them is the connection to mongodb and the other module is the connection to redis for session management. Each module has 2 events in this case error and connect.
  Here is an example from one of the modules:</p>
  
  <pre><code>var sessionStore = new SessionStore(app.get("sessionStore"));
  
  sessionStore.client.on("error", function(err) {
  
      console.error("[SessionStore]:", "connection error:", err.address + ":" + err.port, "for process:", process.pid);
  
      var sessionStoreError = new Error("Session store error");
      sessionStoreError.message = "Session store connection error";
      sessionStoreError.code = err.code;
      sessionStoreError.address = err.address;
      sessionStoreError.port = err.port;
  
      app.emit("error", sessionStoreError);
  
  });
  
  
  sessionStore.client.on("connect", function() {
  
      console.log("[SessionStore]:", "connection established:", app.get("sessionStore").host + ":" + app.get("sessionStore"), "for process:", process.pid);
      app.emit("ready");
  
  });
  </code></pre>
  
  <p>Almost same way happens with mongodb module.</p>
  
  <p>What I would like to achieve (avoiding the pyramid of doom) is something like this but when both redis and mongodb connections from their modules is successful:</p>
  
  <pre><code>app.on("ready", function(){
      app.listen(app.get("port")); 
  });
  </code></pre>
  
  <p>Keep in mind that I could nest each module inside the other and perhaps require sequentialy the modules inside the connect handlers and then emit a final event to app, but this is not elegant I suppose according to my tastes that is.</p>
  
  <p>Is there any elegant way to wait for 2 events and then start the server ?</p>