This Backend Service is intended to keep track of book records and their authors while assessing social popularity of books in the database.
This App is Built with NodeJS powered Express Server to serve as a backend API.
- MongoDB Installation
- Install MongoDB by following the tutorial mentioned here.
- (Optional) Install MongoDBCompass for ease of importing dummy-data to local mongoDB
-
Node JS Runtime - Simply download & install it from here.
-
Node Package Manager
- Run the following command on your terminal
npm install npm@latest -g
- Postman (Optional) - This will be used to demonstrate functionality. Download from here
- Run Mongod server on
localhost
- As instructed in above Mongo Installation tutorial, run the
mongod
server from localhost after installing MongoDB
- Clone the repository to your local machine.
git clone https://github.com/YOUR_USERNAME_HERE/read-to-win-pub.git
- Open Command Line Terminal inside the Root of the Project
ex:
PS E:\read-to-win-pub>
- First, execute
npm install
to install the dependencies - Then, execute
npm run dev
to start the server on local port5000
.
- After setting up above, you can move onto importing the data collections provided in
/dummy_data
dir
├── dummy_data
│ ├── authors.json
│ ├── books.json
- Use following namings to setup the new database when importing
* DB_NAME - `bookStore`
* collections - `authors` & `books`
- Follow, the given tutorial here.
- If this seems hefty, try with MongoDB Compass for easier importing.
This Server consists of two main sub-routes
/author
/books
- BaseURL - 'localhost:5000'
- You can follow these links via
baseurl/links
format.
ex:
POST http://localhost:5000/books
- Note: When passing body parameters, setup
Content-Type
header toapplication/x-www-form-urlencoded
This will be used to carryout Author related transactions in DB.
POST /authors/
- This will be used to create new authors in DB
- this request requires 4 mandatory body parameters
firstName - String, simple+capital-letters-only lastName - String, simple+capital-letters-only email - String , email-format-check[[email protected]] contactNo - Number[0-9], Length[10]
This will be used to carryout Book related transactions in DB.
POST /books/
- This will be used to create new books in DB
- this request requires 4 mandatory body parameters
isbn - String, alphanumerics-only category - String title - String , alphanumerics-only authorId - Author ObjectID - created when adding a new author
GET /books/:isbn
- this will be used to find a book in DB with its ISBN.
- Here,
:isbn
will be replaced with Book's ISBN number.
PUT /books/:id/like
- this will be used to handle when a user likes a specific book.
- Here,
:id
will be replaced with Book's DB ObjectID (Which is set when the book is created). - This will increase likeCount { type: Number, defaultValue:0 } property of the book by 1.
Server Logs are available in logs/
Dir
- There are 2 types of logging in this server
-
Event Logging - This is done for every request in the app and saved in
logs/server.log
-
Author Popularity Logging
- This is done per a 5 mins-step Schedule, where a report is generated on each Author's like Count every 5 mins.
- Saved in
logs/authorPopularity/likesCount.log