forked from andyweiss1982/codespace-node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (20 loc) · 604 Bytes
/
index.js
File metadata and controls
26 lines (20 loc) · 604 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
const express = require('express')
const { Pool } = require('pg')
const app = express()
const port = 3000
let connection = {
host: 'localhost',
port: 5432,
database: 'postgres',
user: 'postgres',
password: 'postgres'
}
if (process.env.DATABASE_URL) {
connection = { connectionString: process.env.DATABASE_URL }
}
const db = new Pool(connection)
app.get('/', async (_, response) => {
const { rows } = await db.query('SELECT NOW();')
response.send(`<h1>The current database time is ${rows[0].now}</h1>`)
})
app.listen(port, () => console.log(`Server on at http://localhost:${port}`))