title: NodeJS express auto created app binding to server
body: <p>I created an express app in NodeJS using <code>express --view=pug expressapp</code>. It created an app.js file</p>
  <h1>app.js</h1>
  <pre><code>var createError = require('http-errors');
  ...
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'pug');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    next(createError(404));
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  //socket setup
  var socket = require('socket.io');
  
  var io = socket(app);
  io.on('connection', function(socket) {
      console.log('made socket connection')
  })
  
  module.exports = app;
  </code></pre>
  <p>at the end I try to bind <code>socket.io</code> to app but it expects to bind to server like so</p>
  <pre><code>var server = app.listen(3000, function() {
      
  });
  
  //socket setup
  var socket = require('socket.io');
  
  var io = socket(server);
  </code></pre>
  <p>I also use <code>nodemon</code> so I run the app using <code>nodemon expressapp</code> and it runs on port 3000. However I can't find where the auto generated express files have setup the server. Because If i try like this</p>
  <pre><code>//socket setup
  var socket = require('socket.io');
  
  var server = app.listen(3000, function() {
          
  });
  
  var io = socket(server);
  </code></pre>
  <p>I get an error that port 3000 is already in use (by itself) I changed it to <code>4000</code> and it works.
  Not ideal, if you know how to connect with port <code>3000</code> will appreciate the assist.</p>