Created
February 1, 2012 05:46
-
-
Save fredrick/1715359 to your computer and use it in GitHub Desktop.
Handling multipart events in Mongoose Query callback?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
function User() { | |
return mongoose.model('users', new mongoose.Schema({ | |
username: String, | |
email: String, | |
name: String | |
})); | |
} | |
exports = module.exports = User; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment