Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
alimay17 committed Jun 17, 2019
1 parent 873b41e commit 2ad5b9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"express": "~4.16.1",
"express-session": "^1.16.2",
"http-errors": "~1.6.3",
"morgan": "~1.9.1"
"morgan": "~1.9.1",
"pg": "^7.11.0"
},
"engines": {
"node": "10.x"
Expand Down
27 changes: 18 additions & 9 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
var express = require('express');
var router = express.Router();
const { Pool } = require('pg')
const Pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: true
});

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('pages/index');
});
router.get('/times', (req, res) => res.send(showTimes()));


showTimes = () => {
let result = ''
const times = process.env.TIMES || 5
for (i = 0; i < times; i++){
result += i + ' '
// get db
router.get('/db', async (req, res) => {
try{
const client = await Pool.connect()
const result = await client.query('SELECT * FROM test_table');
const results = { 'results': (result) ? result.rows : null };
res.render('pages/db', results);
client.release();
} catch(err) {
console.log(err);
res.send("Error " + err);
}
return result;
}
})


module.exports = router;

0 comments on commit 2ad5b9a

Please sign in to comment.