Clone your repository
Go to import-mongo folder
cd /home/project/fullstack-capstone-project/giftlink-backend/util/import-mongo
Duplicate the .env.sample file, naming the new file .env.
This file contains the username and password for MongoDB.
MONGO_URL=mongodb://root:password_of_mongodb_instance@localhost:27017
Change localhost with IP address otherwise it could happen that it won't work.
Testing the code:
- .env file --> mongodDB pw
- new terminal --> cd backend directory
- npm install
- npm start
- launch application in port 3060
- in giftlink-frontend .env file --> paste url from launching step in there
- new terminal go to giftlink-frontend
- npm install
- npm run build
- npm start
- launch application in port 3000
Note (if it does not work):
npm installin backend
In giftlink-backend installnpm install dotenv
npm startin backend
npm installin frontend
npm startin frontend
select "MongoDB CLI" in Skills Network Lab and open a new terminal (directing to import-mongo folder).
Select MongoDB CLI
show databases
use giftdb
show collections
db.gifts.countDocuments() --> result: 16
db.gifts.find({category: 'Living Room'}).limit(2) --> result: 2 objects: Coffe Table and Couch
db.gifts.find({id: '429'}) --> result: 1 object: Side Table
- Several APIs with appropriate endpoints.
- Middleware to handle requests from the front end.
- Integrate gift routes into the main Express application by configuring the middleware
- Express server performs sentiment analysis (anaylzes language to categorize the language as positive, negative, or neutral) by calling external service.
The gifts API handles the routes and endpoints for retrieving all gifts or specific gifts by their ID.
connectToDatabase():
- Connect to MongoDB
- Assign database instance
- Return the database instance
/api/gifts endpoint is implemented so it retrieves the gifts stored with a get() function.
/api/gifts/:id
The search API will contain the search endpoint that allows filtering gifts by name, category, condition, and age.
searchRoutes.js
- Connecting to MongoDB
- Adding the name filter to the query
- Adding other filters to the query such as category, condition, and age.
- Fetching the filtered gifts
- Integrating the search routes in the Express application
- Importing searchRoutes
- Using searchRoutes for the api/search path
Express server that performs sentiment analysis by calling an external service. Natural library using the node package manager (npm).
- Initialize an Express server with the necessary middleware
cd /home/project/fullstack-capstone-project/sentimentnpm install natural
- Create a POST /sentiment endpoint
app.post('/sentiment', async (req, res)
- Extract the sentence parameter from the request body
const { sentence } = req.body;
- Call the external sentiment analysis service using Axios
- Process the external service's response and return the analysis result
- Implement error handling for the Axios request
- Add logging for request processing and errors
- HTML, CSS and React components used
- main page which displays all the gifts
- React components
- main page (home.html, home.css)
- navigation (MainPage.js, Navbar.js)
- register (manage form input states for user details, first name, last name, email, password)
- login (manage form input states for user details, first name, last name, email, password)
- details (details about gifts, user comments, only logged users can access, authentication check, error message)
- search (fetch and display search results from API from other lab, user can search includ text-based input, age range, category, and condition of item)
- Applying Bootstrap classes
- Modifying and Adding missing HTML elements in
giftlink-frontend/public/home.html.