title: How to prevent Node.js from exiting while waiting for a callback?
body: <p>I have code like this:</p>
  
  <pre><code>var client = new mysql.Client(options);
  console.log('Icanhasclient');
  
  client.connect(function (err) {
    console.log('jannn');
    active_db = client;
    console.log(err);
    console.log('hest');
  
    if (callback) {
      if (err) {
        callback(err, null);
      }
  
      callback(null, active_db);
    }
  });
  </code></pre>
  
  <p>My problem is that Node terminates immediately when I run it. It prints 'Icanhasclient', but none of the console.log's inside the callback are called.</p>
  
  <p>(mysql in this example is <a href="https://github.com/felixge/node-mysql" rel="noreferrer">node-mysql</a>.</p>
  
  <p>Is there something that can be done to make node.js wait for the callback to complete before exiting?</p>