Created
June 17, 2011 20:18
-
-
Save al3xandru/1032222 to your computer and use it in GitHub Desktop.
Getting started with VMware CloudFoundry, MongoDB and Node.js
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 record_visit = function(req, res){ | |
/* Connect to the DB and auth */ | |
require('mongodb').connect(mongourl, function(err, conn){ | |
conn.collection('ips', function(err, coll){ | |
/* Simple object to insert: ip address and date */ | |
object_to_insert = { 'ip': req.connection.remoteAddress, 'ts': new Date() }; | |
/* Insert the object then print in response */ | |
/* Note the _id has been created */ | |
coll.insert( object_to_insert, {safe:true}, function(err){ | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write(JSON.stringify(object_to_insert)); | |
res.end('\n'); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment