express/node app quits after one run of function

trying to achieve some instant domain searching for an app, however, the express server quits after just one query. semantically I feel some code needs to be rearranged but I'm unsure of which.

 var ee = new eventEmitter;
 var queries = new Array();
 ee.on('next', next_search);

 function next_search() {
     search(queries[a]);
     if (queries.length == a) process.exit(0);
     ++a;
 }

 function search(x) {
     dns.resolve(x, function (err) {
         if (!err) {
             console.log('bad: ' + x)
             ee.emit('next')
         } else {
             console.log('good: ' + x)
             ee.emit('next')
         }
     });
 }

 app.get('/', function (req, res) {
     res.sendfile(__dirname + '/index.html');
 });

 app.post('/search', function (req, res) {
     domain = req.param('domain');
     queries.push(domain);
     search(queries[queries.length]);
 });

 var a = 0;

 http.createServer(app).listen(app.get('port'), function () {
     console.log("Express server listening on port " + app.get('port'));
 });

I just saw this line in your code

if (queries.length == a) process.exit(0);

You initialized a = 0 and the app will quit when next_search() is executed for the first time for sure.

You aren't starting up express.

http.createServer takes a response function, but you give it app, which is an undefined function.

I assume app is meant to be an express object as in require('express')().

See the documentation for http.createServer at:

http://www.nodejs.org/api/http.html#http_http_createserver_requestlistener

See express.js documentation at

http://expressjs.com/api.html

Try something like this:

var a = 0;

var ee = new eventEmitter;   // pretty sure this is wrong, but I will leave that to you.
var queries = [];
ee.on('next', next_search);

function next_search() {
    search(queries[a]);
    if(queries.length == a) process.exit(0);
    ++a;
 }

function search(x) {
   dns.resolve(x, function (err) {
        if (!err) {
                console.log('bad: ' + x)
                ee.emit('next');
        } else {
                console.log('good: ' + x)
                ee.emit('next');
        }
    });
}

var express = require('express');
var app = express();

app.post('/search', function(req, res) {
    domain = req.param('domain');
    queries.push(domain);
    search(queries[queries.length]);
});

app.get('/', function (req, res) {
     res.sendfile(__dirname + '/index.html');
});

app.get('port'), function(){
    console.log("Express server listening on port " + app.get('port'));
}

app.listen(8080);  // whatever port you want to bind to.