title: When I run mocha tests I always get Error: connect ECONNREFUSED
body: <p>I'm trying to run my app tests with mocha and supertest but I always get Error: connect ECONNREFUSED. </p>
  
  <p>app.js code:</p>
  
  <pre><code>var express = require('express'),
    mongoose = require('mongoose'),
    fs = require('fs'),
    config = require('./config/config');
  
  mongoose.connect(config.db);
  var db = mongoose.connection;
  db.on('error', function () {
    throw new Error('unable to connect to database at ' + config.db);
  });
  
  var modelsPath = __dirname + '/app/models';
  fs.readdirSync(modelsPath).forEach(function (file) {
    if (file.indexOf('.js') &gt;= 0) {
      require(modelsPath + '/' + file);
    }
  });
  
  var app = express();
  
  require('./config/express')(app, config);
  require('./config/routes')(app);
  
  app.listen(config.port);
  
  exports.app = app;
  console.log('LISTEN ON http://localhost:3000/')
  </code></pre>
  
  <p>test.js code:</p>
  
  <pre><code>var should = require('should'); 
  var assert = require('assert');
  var request = require('supertest');
  var mongoose = require('mongoose');
  var app = require('../../../app').app;
  
  describe('Categories', function() {
      it('- POST is testing', function(done) {
          request(app)
          .post('http://localhost:3000/categories')
          .send({title:'test', text:'test'})
          .end(function(e, res) {
              console.log(e, res);
          });
      });
  });
  </code></pre>
  
  <p>Test output:</p>
  
  <pre><code>LISTEN ON http://localhost:3000/
  
  
    Categories
  { [Error: connect ECONNREFUSED]
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect' } undefined
      1) - POST is testing
  
  
    0 passing (2s)
    1 failing
  
  Done, but with warnings.
  </code></pre>
  
  <p>Could you give any clue why this happend?</p>
  
  <p>Thank you in advance!</p>
  
  <p>Topicus</p>