LearnBoost/mongoose — Issue #703: Cannot listen/handle EventEmitter in Model.find callback
Author: wayoutmind
Created: 2012-02-01 06:16:14+00:00
State: open

I'm having trouble handing events from a library such as Formidable. Why is this so?

Example:

`models.js`

```javascript
var mongoose = require('mongoose');

function User() {
return mongoose.model('users', new mongoose.Schema({
username: String,
email: String,
name: String
}));
}

exports = module.exports = User;
```

`server.js`

```javascript
/** Example HTTP server
*/

var http = require('http'),
mongoose = require('mongoose'),
formidable = require('formidable'),
models = require('./models');

mongoose.connect('mongodb://localhost/test');

var User = new models.User();
var form = new formidable.IncomingForm();

http.createServer(function(request, response) {
User.findOne({ username: 'wayoutmind' }, function(error, user) {
// Does not print to console, Event listener blackhole?
form.on('field', function(name, value) {
console.log(name + ':' + value);
})
form.parse(request);
});
}).listen(1337);
```