-
-
Save blakmatrix/f71032e92a0b87d88f98 to your computer and use it in GitHub Desktop.
This file contains 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 http = require('http'); | |
var mongoose = require('mongoose'); | |
var db = mongoose.connect('mongodb://nodejitsu_blakmatrix:rtusu8k1uqqrdtdgtude1k0hh7@ds043947.mongolab.com:43947/nodejitsu_blakmatrix_nodejitsudb7674993586'); | |
//mongodb://nodejitsu_blakmatrix:rtusu8k1uqqrdtdgtude1k0hh7@ds043947.mongolab.com:43947/nodejitsu_blakmatrix_nodejitsudb7674993586 | |
var Schema = mongoose.Schema; | |
var User = new Schema({ | |
first_name: String, | |
last_name: String, | |
ip: String | |
}); | |
var UserModel = mongoose.model('User', User); | |
http.createServer(function (req, res) { | |
var record = new UserModel(); | |
record.first_name = 'hello'; | |
record.last_name = 'world'; | |
record.ip = req.headers["x-forwarded-for"] || '0.0.0.0'; | |
record.save(function (err, rec) { | |
var id = rec['_id']; | |
UserModel.findById(id, function(err, user) { | |
console.log( "User => _id: " + user._id + ", first_name: " + user.first_name + ", last_name: " + user.last_name + ", ip: " + user.ip); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end("User => _id: " + user._id + ", first_name: " + user.first_name + ", last_name: " + user.last_name+ ", ip: " + user.ip +'\n'); | |
}); | |
}); | |
//res.writeHead(200, {'Content-Type': 'text/plain'}); | |
//res.end('Hello World\n'); | |
}).listen(8080); | |
console.log('Server running...');//http://blakmatrix.mongoose-test.jit.su |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment