Last active
October 18, 2018 18:06
-
-
Save jkutner/ee58306f76863e08f416fca3c5236115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cool = require('cool-ascii-faces') | |
const express = require('express') | |
const path = require('path') | |
const PORT = process.env.PORT || 5000 | |
express() | |
.use(express.static(path.join(__dirname, 'public'))) | |
.set('views', path.join(__dirname, 'views')) | |
.set('view engine', 'ejs') | |
.get('/', (req, res) => res.render('pages/index')) | |
.get('/cool', (req, res) => res.send(cool())) | |
.listen(PORT, () => console.log(`Listening on ${ PORT }`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Pool } = require('pg'); | |
const pool = new Pool({ | |
connectionString: process.env.DATABASE_URL, | |
ssl: true | |
}); | |
const cool = require('cool-ascii-faces') | |
const express = require('express') | |
const path = require('path') | |
const PORT = process.env.PORT || 5000 | |
express() | |
.use(express.static(path.join(__dirname, 'public'))) | |
.set('views', path.join(__dirname, 'views')) | |
.set('view engine', 'ejs') | |
.get('/', (req, res) => res.render('pages/index')) | |
.get('/cool', (req, res) => res.send(cool())) | |
.get('/times', (req, res) => { | |
let result = '' | |
const times = process.env.TIMES || 5 | |
for (i = 0; i < times; i++) { | |
result += i + ' ' | |
} | |
res.send(result) | |
}) | |
.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.error(err); | |
res.send("Error " + err); | |
} | |
}) | |
.listen(PORT, () => console.log(`Listening on ${ PORT }`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cool = require('cool-ascii-faces') | |
const express = require('express') | |
const path = require('path') | |
const PORT = process.env.PORT || 5000 | |
express() | |
.use(express.static(path.join(__dirname, 'public'))) | |
.set('views', path.join(__dirname, 'views')) | |
.set('view engine', 'ejs') | |
.get('/', (req, res) => res.render('pages/index')) | |
.get('/cool', (req, res) => res.send(cool())) | |
.get('/times', (req, res) => { | |
let result = '' | |
const times = process.env.TIMES || 5 | |
for (i = 0; i < times; i++) { | |
result += i + ' ' | |
} | |
res.send(result) | |
}) | |
.listen(PORT, () => console.log(`Listening on ${ PORT }`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table test_table (id integer, name text); | |
insert into test_table values (1, 'hello database'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment