The aim of this project was to build a small web app with functionality similar to: https://personal-library.freecodecamp.rocks
- HTML
- JavaScript with Node.js / NPM for package management.
- Express web framework to build the web API.
- mongodb for interacting with a MongoDB Atlas database.
- Bootstrap for styling with some custom CSS.
- FontAwesome for icons.
- Mocha test framework with Chai assertions for testing.
- nodemon for automatic restarting of server during development.
-
User Story #1: You can send a
POST
request to/api/books
withtitle
as part of the form data to add a book. The returned response will be an object with thetitle
and a unique_id
as keys. Iftitle
is not included in the request, the returned response should be the stringmissing required field title
. -
User Story #2: You can send a
GET
request to/api/books
and receive a JSON response representing all the books. The JSON response will be an array of objects with each object (book) containingtitle
,_id
, andcommentcount
properties. -
User Story #3: You can send a
GET
request to/api/books/{_id}
to retrieve a single object of a book containing the propertiestitle
,_id
, and acomments
array (empty array if no comments present). If no book is found, return the stringno book exists
. -
User Story #4: You can send a
POST
request containingcomment
as the form body data to/api/books/{_id}
to add a comment to a book. The returned response will be the books object similar toGET /api/books/{_id}
request in an earlier test. Ifcomment
is not included in the request, return the stringmissing required field comment
. If no book is found, return the stringno book exists
. -
User Story #5: You can send a
DELETE
request to/api/books/{_id}
to delete a book from the collection. The returned response will be the stringdelete successful
if successful. If no book is found, return the stringno book exists
. -
User Story #6: You can send a
DELETE
request to/api/books
to delete all books in the database. The returned response will be the stringcomplete delete successful
if successful. -
User Story #7: 11 Functional Tests covering all routes and methods with valid and invalid input are complete and passing:
- Create a Book with a valid title:
POST /api/books
- Create a Book with no title given:
POST /api/books
- Get all Books:
GET /api/books
- Get a single Book's details with valid id:
GET /api/books/:id
- Get a single Book's details with invalid id:
GET /api/books/:id
- Add a Comment to a Book with valid id and comment:
POST /api/books/:id
- Add a Comment to a Book with valid id and no comment:
POST /api/books/:id
- Add a Comment to a Book with invalid id:
POST /api/books/:id
- Delete a Book with valid id:
DELETE /api/books/:id
- Delete a Book with invalid id:
DELETE /api/books/:id
- Delete all Books:
DELETE /api/books/:id
- Create a Book with a valid title:
The third Free Code Camp: Quality Assurance Project is a simple Personal Library App and API. Users can:
-
Add Books to the Library by submitting the relevant form on the API / UI view, or by sending a POST request to
/api/books
with a body containing a url encodedtitle
field - the title of the book. -
Add Comments to a Book by submitting the relevant form on the API / UI view, or by sending a POST request to
/api/books/<BOOK _id>
, with a body containing a url encoded field of 'comment' - the comment for the book. -
View all Books in the library by using the UI view or sending a GET request to
/api/books
. -
View a single Book's details (title, _id and comments) using the UI view or by sending a GET request to
/api/books/<BOOK _id>
. -
Delete a Book using the UI view or by sending a DELETE request to
/api/books/<BOOK _id>
. -
Delete all Books using the UI view or by sending a DELETE request to
/api/books
.
A test suite has been written for the app:
tests/2_functional-tests.js
contains functional tests of the application routes (GET, POST and DELETE requests to/api/books/:book_id?
).
-
server.js
- the main entry point of the application, an express web server handling the routes defined in the specification. -
/routes/api.js
- contains the major API routes for the express web app. -
/controllers
- contains thebookController.js
andcommentController.js
middleware, with methods to carry out the Create, Read and Delete operations on Books / Comments as requested. -
public/
- contains static files for the web app (stylesheet, logo, favicons etc), served by express usingexpress.static()
.client.js
containsjQuery
scripts for handling updates to the UI view of the app, and is loaded byindex.html
.
-
views/
- contains the single html page for the web app,index.html
, which is served by express onGET
requests to `/ -
tests/
- contains the test suite for the application.
Requires Node.js / NPM in order to install required packages. After downloading the repo, install required dependencies with:
npm install
To run the app locally, a valid MongoDB database URI and a database name are required to be entered as environmental variables (MONGO_URI
, DB_NAME
), which can be done via a .env
file (see sample.env). One possible MongoDB service is MongoDB Atlas.
A development mode (with auto server restart on file save), can be started with:
npm run dev
The application can then be viewed at http://localhost:3000/
in the browser.
To start the server without auto-restart on file save:
npm start
The initial boilerplate for this app can be found at https://github.com/freeCodeCamp/boilerplate-project-library
Instructions for building the project can be found at https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/personal-library