Alternative Product Insights is a web application designed to help users search and recommend alternative products. This server-side application is built using Node.js, Express, MongoDB, and JWT for authentication.
To get started with the Alternative Product Insights server, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/altprodinsights-server.git cd altprodinsights-server
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and add your MongoDB credentials and other configuration details:PORT=5000 DB_USER=your_db_user DB_PASS=your_db_password ACCESS_TOKEN_SECRET=your_access_token_secret NODE_ENV=development
The server configuration is managed through environment variables. Ensure you have the following variables set in your .env
file:
PORT
: The port on which the server will run.DB_USER
: Your MongoDB username.DB_PASS
: Your MongoDB password.ACCESS_TOKEN_SECRET
: The secret key for JWT token signing.NODE_ENV
: The environment mode (development or production).
- Endpoint:
POST /jwt
- Description: Generate a JWT token for a user.
- Request Body:
{ "email": "user@example.com" }
- Endpoint:
GET /logout
- Description: Clear the JWT token from cookies.
- Endpoint:
POST /queries
- Description: Add a new query.
- Request Body:
{ "productName": "string", "productBrand": "string", "productImageUrl": "string", "queryTitle": "string", "buyingReasonDetails": "string", "email": "string" }
- Endpoint:
GET /queries
- Description: Retrieve all queries.
- Endpoint:
GET /queriess/:email
- Description: Retrieve queries by user email.
- URL Parameters:
email
- User's email.
- Endpoint:
GET /queries/:id
- Description: Retrieve a single query by ID.
- URL Parameters:
id
- Query ID.
- Endpoint:
PATCH /myQueries/update/:id
- Description: Update details of a query.
- URL Parameters:
id
- Query ID. - Request Body: Same as Add a Query.
- Endpoint:
DELETE /myQueries/delete/:id
- Description: Delete a query by ID.
- URL Parameters:
id
- Query ID.
- Endpoint:
POST /recommendations
- Description: Add a new recommendation.
- Request Body:
{ "queryId": "string", "recommendationDetails": "string", "RecommenderEmail": "string" }
- Endpoint:
GET /recommendations
- Description: Retrieve all recommendations.
- Endpoint:
GET /recommendations/:email
- Description: Retrieve recommendations by recommender's email.
- URL Parameters:
email
- Recommender's email.
- Endpoint:
DELETE /recommendations/delete/:id
- Description: Delete a recommendation by ID.
- URL Parameters:
id
- Recommendation ID.
- Endpoint:
GET /ForMeRecommendations/:email
- Description: Retrieve recommendations for a specific user.
- URL Parameters:
email
- User's email.
- Endpoint:
GET /allRecommendations/:id
- Description: Retrieve recommendations for a specific query.
- URL Parameters:
id
- Query ID.
-
Start the server:
npm start
-
Access the server: Open your browser and navigate to
http://localhost:5000
.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or new features.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to customize this `README.md` file as per your specific requirements and add any additional information as needed.