-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
30 lines (25 loc) · 808 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
const Joi = require('joi'); //validates
const express = require('express');
const app = express();
const books = require('./routes/books');
const home = require('./routes/home');
const bodyParser = require('body-parser');
const sqlDatabase = require('./database');
app.set('view engine', 'pug');
app.set('views', './views')
//middleware
app.use(express.json());
app.use(bodyParser.urlencoded({extended: false})); // key=value&key=value
app.use(express.static('public'));
app.use('/api/books', books);
app.use('/', home);
//MySQL Database connection
sqlDatabase.execute('SELECT * FROM books')
.then(result => {
//console.log(result[0]);
})
.catch(err => {
console.log(err);
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}.`));