title: Setting up Sequelize
body: <p>I am new to programmming getting used to node and setting up database for first time. So please give some pointers as to what I am doing wrong.I created a default express app. And ran it getting this error.</p>
  
  <pre><code>events.js:72
          throw er; // Unhandled 'error' event
                ^
  Error: listen EADDRINUSE
      at errnoException (net.js:904:11)
      at Server._listen2 (net.js:1042:14)
      at listen (net.js:1064:10)
      at Server.listen (net.js:1138:5)
      at Function.module.exports (D:\Developer\DurexData\app.js:69:30)
      at null.&lt;anonymous&gt; (D:\Developer\DurexData\node_modules\sequelize\lib\emitt
  ers\custom-event-emitter.js:105:15)
      at emit (events.js:95:17)
      at module.exports.CustomEventEmitter.emit (D:\Developer\DurexData\node_modul
  es\sequelize\lib\emitters\custom-event-emitter.js:61:33)
      at module.exports.finish (D:\Developer\DurexData\node_modules\sequelize\lib\
  query-chainer.js:142:30)
      at exec [as fct] (D:\Developer\DurexData\node_modules\sequelize\lib\query-ch
  ainer.js:96:16)
  </code></pre>
  
  <p>This is the Program
  <strong>app.js</strong></p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  var tasks = require('./routes/task');
  var http = require('http')
      ,   db = require('./models')
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', routes);
  app.use('/users', users);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
  });
  
  // error handlers
  
  // development error handler
  // will print stacktrace
  if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
          res.status(err.status || 500);
          res.render('error', {
              message: err.message,
              error: err
          });
      });
  }
  
  // production error handler
  // no stacktraces leaked to user
  app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
          message: err.message,
          error: {}
      });
  });
  
  db
    .sequelize
    .sync({ force: true })
    .complete(function(err) {
      if (err) {
        throw err[0]
      } else {
        http.createServer(app).listen(app.get('port'), function(){
          console.log('Express server listening on port ' + app.get('port'))
        })
      }
    })
  
  module.exports = app;
  </code></pre>
  
  <p><strong>models/index.js</strong></p>
  
  <pre><code>var fs        = require('fs')
    , path      = require('path')
    , Sequelize = require('sequelize')
    , lodash    = require('lodash')
    , config    = require('../config/db_config')
    , sequelize = new Sequelize(config.database, config.username, config.password, {
      database: config.database, 
      username: config.username, 
      password: config.password,
      host: config.host,
      port: config.port,
      dialect: 'mysql'
    })
    , db        = {};
  
  fs
    .readdirSync(__dirname)
    .filter(function(file) {
      return (file.indexOf('.') !== 0) &amp;&amp; (file !== 'index.js')
    })
    .forEach(function(file) {
      var model = sequelize.import(path.join(__dirname, file))
      db[model.name] = model
    });
  
  Object.keys(db).forEach(function(modelName) {
    if ('associate' in db[modelName]) {
      db[modelName].associate(db)
    }
  });
  
  module.exports = lodash.extend({
    sequelize: sequelize,
    Sequelize: Sequelize
  }, db);
  </code></pre>
  
  <p><strong>routes/index.js</strong></p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET home page. */
  router.get('/', function(req, res) {
    res.render('index', { title: 'Express' });
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>routes/user.js</strong></p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET users listing. */
  router.get('/', function(req, res) {
    res.send('respond with a resource');
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Thank You Everyone
  The Problem was solved I added http create server from sequelize code and had app.listen in ./bin/www didn't notice it that was what was giving this error.</p>