title: Getting a callback when asyncronous tasks are completed
body: <p>I'm creating a basic migration class for my app.</p>
  
  <pre><code>// commands/migrate.js
  const Question = require('../models/Question');
  
  class Migrate
  {
      constructor() {
  
      }
  
      run() {
          console.log("Deleting entries...");
  
          Question.remove({}, (err) =&gt; {
              if (err) {
                  throw err;
              }
  
              console.log("Entries deleted. Seeding...");
  
              for (var i = 0; i &lt;= 20; i++) {
                  new Question({
                      id: i,
                      title: "Who are you?",
                      answers: [
                          "Answer 1",
                          "Answer 2",
                          "Answer 3",
                          "Answer 4"
                      ],
                      correctAnswer: 0
                  }).save((err, entry) =&gt; {
  
                      if (err) {
                          throw err;
                          return;
                      }
  
                      console.log(entry.id + "seeded!");
                  });
              }
          });
      }
  }
  
  module.exports = () =&gt; {
      return new Migrate()
  }
  </code></pre>
  
  <p>My <code>server.js</code> looks like this.</p>
  
  <pre><code>if (typeof process.argv[2] !== "undefined") {
      switch (process.argv[2]) {
          case "migrate":
              require('./commands/' + process.argv[2] + '.js')().run()
              break;
  
          default:
              throw new Error("Invalid command.");
      }
  
      return;
  }
  </code></pre>
  
  <p><code>Question</code> model relies on <code>Mongoose</code>. Right now I get the following console log.</p>
  
  <pre><code>Deleting entries...
  Entries deleted. Seeding...
  0 seeded!
  ...
  20 seeded!
  </code></pre>
  
  <p>However, I want to add one more line at the bottom when task is completed, so it looks like this.</p>
  
  <pre><code>Deleting entries...
  Entries deleted. Seeding...
  0 seeded!
  ...
  20 seeded!
  Command successful. Process exiting. // process.exit(0)
  </code></pre>
  
  <p>Is there any way to do this? Should I throw a callback when last query successfully completes or something?</p>