forked from alikillen/Libro_app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
75 lines (62 loc) · 1.6 KB
/
app.js
File metadata and controls
75 lines (62 loc) · 1.6 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require('express')
var exphbs = require('express-handlebars');
const app = express()
const bodyParser = require("body-parser")
const cors = require("cors")
const mongoose = require("mongoose")
const bookRouter = require("./routes/book_routes")
const api_helper = require('./API_helper')
// import {v4 as uuidv4} from 'uuid'
const port = 3000
app.use(cors())
app.use(bodyParser.json())
const dbConn = process.env.MONGODB_URI || "mongodb://localhost/libro_app"
// when we need to deploy:
// if(process.env.NODE_ENV !== "production"){
// require("dotenv").config();
// }
mongoose.connect(
dbConn,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
},
err => {
if (err) {
console.log("Error connecting to database", err)
} else {
console.log("Connected to database!")
}
}
)
app.engine('handlebars', exphbs());
app.set('view engine', 'handlebars');
app.get('/', (req, res) => {
res.render("home");
})
app.get("/search", (req, res)=>{
res.render("search")
})
app.get("/register", (req,res)=> {
res.render("register")
})
app.get("/books", (req, res)=> {
res.render("books")
})
app.get("/login", (req, res)=>{
res.render("login")
})
// app.get('/getAPIResponse', (req, res) => {
// api_helper.make_API_call('https://jsonplaceholder.typicode.com/todos/1')
// .then(response => {
// res.json(response)
// })
// .catch(error => {
// res.send(error)
// })
// })
app.use("/books", bookRouter)
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})