-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (29 loc) · 848 Bytes
/
app.js
File metadata and controls
32 lines (29 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require('express')
const app = express()
var pg = require('pg')
var format = require('pg-format')
var PGUSER = 'Antonio'
var PGDATABASE = 'example'
var age = 732
var config = {
user: PGUSER, // name of the user account
database: PGDATABASE, // name of the database
max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed
}
var pool = new pg.Pool(config)
var myClient
pool.connect(function (err, client, done) {
if (err) console.log(err)
app.listen(3000, function () {
console.log('listening on 3000')
})
myClient = client
var ageQuery = format('SELECT * from numbers WHERE age = %L', age)
myClient.query(ageQuery, function (err, result) {
if (err) {
console.log(err)
}
console.log(result.rows[0])
})
})