title: Node.JS: Make module runnable through require or from command line
body: <p>I have a script <code>setupDB.js</code> that runs asynchronously and is intended to be called from command line. Recently, I added test cases to my project, some of which require a database to be set up (and thus the execution of aforementioned script).</p>
  
  <p>Now, I would like to know when the script has finished doing its thing. At the moment I'm simply waiting for a few seconds after requiring <code>setupDB.js</code> before I start my tests, which is obviously a bad idea.</p>
  
  <p>The problem with simply exporting a function with a callback parameter is that it is important that the script can be run without any overhead, meaning no command line arguments, no additional function calls etc., since it is part of a bigger build process.</p>
  
  <p>Do you have any suggestions for a better approach?</p>