-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (24 loc) · 831 Bytes
/
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
const express = require('express');
const app = express();
const path = require('path');
const request = require('request');
const API = "AIzaSyAHmJnCVKa6jhw5kPxg-PfQxxI_Eu1Bpts" ;
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.get('/results', (req, res)=> {
let query = req.query.search;
request('https://www.googleapis.com/books/v1/volumes?q='+query+'&key='+API, (error, response, body) => {
if(error) {
console.log(error);
}
let data = JSON.parse(body);
res.render('books', {data:data, searchQuery:query});
});
});
app.get('/search', (req,res)=> {
res.render('search');
});
app.listen(4400, ()=>{
console.log('Server started at port 4400.');
});