-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (37 loc) · 1.21 KB
/
server.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
48
49
const mongoose = require('mongoose');
const path = require("path");
const express = require('express');
const routes = require("./routes");
const bodyParser = require('body-parser');
const logger = require('morgan');
const { Client } = require('pg');
require('dotenv').config();
const app = express();
const API_PORT = process.env.API_PORT || 3001;
// this is our postGres database
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
client.connect();
client.query('SELECT table_schema,table_name FROM information_schema.tables;', (err, res) => {
if (err) throw err;
for (let row of res.rows) {
console.log(JSON.stringify(row));
}
client.end();
});
// (optional) only made for logging and
// bodyParser, parses the request body to be a readable json format
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(logger('dev'));
if (process.env.NODE_ENV === "production") {
// Express will serve up production assets
app.use(express.static(__dirname + "client/build"));
}
app.use(routes)
// start the API server
app.listen(API_PORT, () => console.log(`Api server now listening on PORT ${API_PORT}`));