title: EBUSY error trying to delete database file
body: <p>I'm trying to create then delete an SQLite database using the before/after Mocha hooks. Using <a href="https://github.com/mapbox/node-sqlite3" rel="nofollow noreferrer">the Node.js SQLite library</a> I'm getting 'Error: EBUSY: resource busy or locked...' when calling <code>fs.unlinkSync(DB_PATH)</code>.</p>
  <p>I'm able to delete the file afterwards, so has to do with the Node.js SQLite library not releasing the file descriptor. How to create then close a database connection and delete the database file in the same program, or does the program have to exit before deleting the file?  The code (Windows 10, Node.js v6.10.0):</p>
  <pre><code>var sqlite3 = require('sqlite3');
  
  var fs = require('fs');
  var childProc = require('child_process');
  
  before(function() {
      childProc.execSync(&quot;sqlite3 ./test_db_data/test_db.sqlite3 &lt; ./load_data/sql/init_model.sql&quot;).toString()
  });
  
  after(function() {
      fs.unlinkSync(DB_PATH);
  });
  
  describe('tests', function() {
      var db;
      before(function(done) {
  
          // set up database
          new Promise(function(resolve, reject) {
              console.log(&quot;Running promise&quot;);
  
              db = new sqlite3.Database(DB_PATH, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, function(err) {
                  if (err) {
                      throw new Error(&quot;Couldn't create test database.&quot;);
                  }
                  resolve();
              });
  
          }).then(function() {
              server = app.start(DB_PATH, done);
          }, function(err) {
              console.log(&quot;Error opening database&quot;);
              done(err);
          });
      });
  
      after(function(done) {
  
          //stop server
          server.close();
  
          // delete database
          db.close(function(err) {
              if (!err) {
                  done();
              } else {
                  console.log(err);
                  throw new Error(&quot;Couldn't close database connection.&quot;);
              }
          });
      });
  </code></pre>