title: Mongoose Connection Keeps Closing
body: <p>I have a Node.js app that should run forever and am creating a single mongodb connection. However the connection keeps closing after a few seconds and crashing the app. I've stripped all the code back to just the create connection method. App code:</p>
  
  <pre><code>var mongoose = require('mongoose'),
      db = mongoose.createConnection("mongodb://localhost:28017/mwa");
  </code></pre>
  
  <p>Then after a few seconds I get:</p>
  
  <pre><code>node.js:201
      throw e; // process.nextTick error, or 'error' event on first tick
            ^
  Error: connection closed
      at [object Object].&lt;anonymous&gt; (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:557:24)
      at [object Object].emit (events.js:88:20)
      at [object Object].&lt;anonymous&gt; (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:109:15)
      at [object Object].emit (events.js:70:17)
      at Socket.&lt;anonymous&gt; (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:427:12)
      at Socket.emit (events.js:67:17)
      at Array.0 (net.js:335:10)
      at EventEmitter._tickCallback (node.js:192:40)
  </code></pre>