Port stops working after each use while using node.js and socket.io

Here is my app.js file

/**
 * Module dependencies.
 */

var io = require('socket.io'),
    express = require('express'),
    path = require('path'),
    jquery = require('jquery'),
    routes = require('./routes');


/**
* Create app
*/

var app = express()
  , server = require('http').createServer(app)  
  , io = io.listen(server);

/**
* Configure app
*/ 
app.configure(function(){ 
    app.set('port', 2121);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.static(path.join(__dirname, 'public')));

});

// set both servers listening
server.listen( app.get('port') );


/**
* App gets
*/

app.get('/', routes.index );


console.log("listining on port " + app.get('port'));

io.set('log level', 1); // this gets rid of all the internal socket messages

io.sockets.on('connection', function(socket){
    console.log('made connection');


});

and in my index.js file which loads when index is rendered I have

$(document).ready( function () {
    var socket = io.connect('http://localhost:2121');

});

The problem I am having is that this code will execute once, with the terminal displaying

My-MacBook-Pro-3:board_demo home$ node app.js 
   info  - socket.io started
listining on port 2121
made connection

However if I quit the process ^z and try to run the code again node app.js I get

My-MacBook-Pro-3:one_board_demo home$ node app.js 
   info  - socket.io started
listining on port 2121
   warn  - error raised: Error: listen EADDRINUSE

I then switch the port and the process repeats.

What could be causing this? I took most of the code I'm using now from a project I made before which did not have this problem.

Thanks for the help