title: CouchDB Database create/delete
body: <p>I have a NodeJS application and I have a problem using nano to create/delete a database. I want to check if there is a database with the users name. If there is a database I would like to clear it so I destroy it and create a new one.</p>
  <pre><code>module.exports.createDB = function () {
    try {
      nano.db.list().then((body) =&gt; {
        // body is an array
        body.forEach((db) =&gt; {
          if(db == getUser.username){
            nano.db.destroy(getUser.username)
          }
        });
      });
      nano.db.create(getUser.username).then((body) =&gt; {
        nano.use(getUser.username).insert(
          { &quot;views&quot;: 
            { &quot;webview&quot;: 
              { &quot;map&quot;: &quot;function (doc) {\n  emit(doc.msg, 1);\n}&quot;, &quot;reduce&quot;: &quot;_count&quot; }
            }
          }, '_design/output', function (error, response) {
            console.log(&quot;Design Created&quot;);
          });
      })
    } catch (error) {
      console.log(error);
    }
  }
  </code></pre>
  <p>If there is no database with this name it works fine but if there is a database with the same name i get the error:</p>
  <p>(node:33354) UnhandledPromiseRejectionWarning: Error: The database could not be created, the file already exists.</p>
  <p>But I don't know why because I destroy this database before?</p>