You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
brianc edited this page Mar 7, 2013
·
17 revisions
This code should be able to be copy/pasted to give you a sample app running on your machine
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)