Skip to content

Instantly share code, notes, and snippets.


koistya/server.js Secret

Created Feb 26, 2016
What would you like to do?
Async node-postgres sample code
import express from 'express';
import db from './core/db';
const app = express();
const port = process.env.PORT || 3000;
app.get('/visits', (req, res, next) => {
db.connect(async ({ query } => {
await query('INSERT INTO visit (date) VALUES ($1)', new Date());
const result = await query('SELECT COUNT(date) AS count FROM visit');
res.send(`You are visitor number ${result.rows[0].count}.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.