-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (36 loc) · 1.25 KB
/
app.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
const express = require('express')
const app = express()
const path = require('path')
const fetch = require('node-fetch')
const PORT = process.env.PORT || 8000; // process.env accesses heroku's environment variables
app.use(express.static('public'))
app.get('/', (request, res) => {
res.sendFile(path.join(__dirname, 'index.html'))
})
// // create route to get single book by its isbn
// app.get('/books/:isbn', (request, response) => {
// // make api call using fetch
// fetch(`http://openlibrary.org/api/books?bibkeys=ISBN:${request.params.isbn}&format=json&jscmd=data`)
// .then((response) => {
// return response.text();
// }).then((body) => {
// let results = JSON.parse(body)
// console.log(results) // logs to server
// response.send(results) // sends to frontend
// });
// });
// // create a search route
// app.get('/search', (request, response) => {
// fetch(`http://openlibrary.org/search.json?q=${request.query.string}`)
// .then((response) => {
// return response.text();
// }).then((body) => {
// let results = JSON.parse(body)
// console.log(results)
// response.send(results)
// });
// });
app.listen(PORT, () => {
console.log(__dirname);
console.log(`listening on ${PORT}`)
})