-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
47 lines (38 loc) · 944 Bytes
/
app.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// var express = require('express');
// var app = express();
// app.get('/', function (req, res) {
// res.send('Hello World!');
// });
// app.listen(3000, function () {
// console.log('Example app listening on port 3000!');
// });
import express from 'express'
import pool from './db'
const app = express()
// Home Route
app.get('/', async (req, res) => {
res.json({
message: 'Docker Service :D'
})
})
// Route to test database connection
app.get('/desserts', async (req, res) => {
let conn
try {
conn = await pool.getConnection()
let sql = `SELECT * FROM desserts`
let result = await conn.query(sql)
res.send(result)
} catch (error) {
throw error
} finally {
if (conn) {
conn.release()
}
}
})
const port = process.env.PORT || 8000
// Listening Server
app.listen(port, () => {
console.log(`Server is up at port:${port}`)
})