-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.js
33 lines (28 loc) · 895 Bytes
/
index.js
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
33
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const { Pool } = require('pg')
app.locals.octicons = require("@primer/octicons");
const pool = new Pool({
user: process.env.POSTGRES_USER,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
host: process.env.HOST,
port: 5432
});
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(express.static('public'))
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
pool.query('SELECT * FROM haikus ORDER BY id', (err, haikus) => {
res.render('index', {haikus: haikus.rows});
});
});
app.post('/heart', (req, res) => {
pool.query('UPDATE haikus SET hearts = hearts + 1 WHERE id = $1', [req.body.id], () => {
res.send('Success');
});
});
app.listen(port);
console.log(`Server running on http://localhost:${port}`)