title: Run async code from command line, node js
body: <p>I have a function that generates some test data and inserts it to a mongodb:</p>
  
  <pre><code>'use strict';
  const CvFaker = require('./cv-faker');
  const mongoose = require('mongoose');
  require('../models/cv_model.js');
  
  module.exports.init = function(){
    var cvfaker = new CvFaker();
    cvfaker.genCvs(100);
  
    mongoose.model('cv').create(cvfaker.cvs, (err, createdCvs) =&gt; {
      if(err){
        console.log('something went wrong');
      }
  
    })
  };
  </code></pre>
  
  <p>I want to execute this code from the command line:</p>
  
  <pre><code>node -e 'require("./create-mock-db").init()'
  </code></pre>
  
  <p>The function executes, but it does not wait for the function to complete since it is async. How do I make it wait for the function to complete?</p>
  
  <p>This is not working either: </p>
  
  <pre><code>module.exports.init = function(cb){ ...
  ..
  cb();
  
  node -e 'require("./create-mock-db").init(function(){})'
  </code></pre>