-
-
Save koistya/f50f718e35799b1895fd to your computer and use it in GitHub Desktop.
Async node-postgres sample code
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
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}.`); | |
}).catch(next); | |
}); | |
app.listen(port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment