forked from brianc/node-postgres
- Notifications
You must be signed in to change notification settings - Fork 0
Example
brianc edited this page Mar 7, 2013
·
17 revisions
You'll need to first "create table visit (date date)" in your postgres database
varhttp=require('http');varpg=require('pg');varserver=http.createServer(function(req,res,next){pg.connect(function(err,client,done){varhandleError=function(err){if(!err)returnfalse;done(client);next(err);returntrue;};client.query('INSERT INTO visit (date) VALUES ($1)',[newDate()],function(err,result){if(handleError(err))return;client.query('SELECT COUNT(date) AS count FROM visit',function(err,result){if(handleError(err))return;done();res.writeHead(200,{'content-type': 'text/html'});res.end('You are visitor number '+result.rows[0].count);});});});})server.listen(3001)