In this project, I created a new React-based Google Books Search app. This project implemented React components, worked with helper/util functions, and utilized React lifecycle methods to query and display books based on user searches. I also used Node, Express and MongoDB so that users can save books to review or purchase later.
- Copy the repo from GitLab using your ssh key
- Run Git bash
- Type in "code ." to open Visual Studios Code
- Install dependencies
- Type "npm start"
var router = require("express").Router();
var Book = require("../../models/Book")
var bookGet;
// Get all saved books as json
router.get("/api/Book", (req, res) => {
Book.find({})
.sort()
.then(dbBook => {
res.json(dbBook);
})
.catch(err => {
res.status(400).json(err);
});
});
// Save new books to database
router.post("/api/Book/", ({ body }, res) => {
Book.insert(body)
.then(dbBook => {
res.json(dbBook);
})
.catch(err => {
res.status(400).json(err);
});
})
// Delete books from database by mongo _id
router.delete("/api/Book/:id", ({ body }, res) => {
Book.deleteOne(body)
.then(dbBook => {
res.json(dbBook);
})
.catch(err => {
res.status(400).json(err);
});
})
// * get everything upon page load. go through mongoose and retrieve everything
module.exports = router;
This code shows the different routes we needed to create in order to send information to the mongoDb database. We used router.get and router.delete to retrieve all books and to delete specific books.
- Bootstrap
- Javascript
- HTML/CSS
- jQuery
- Font Awesome
- React
- Mongoose
- Node
MIT
- Austin Woo
- Jerome Chenette (Instructor)
- Manuel Nunes (TA)
- Mahisha Manikandan (TA)
- UC Berkeley Coding Bootcamp