This project is a simple Express.js application that fetches blog data from a third-party API, performs analytics on the data, and provides a blog search functionality. It also includes error handling and caching capabilities.
Before you can run this project, you need to have the following software installed on your machine:
- Node.js: Download and Install Node.js
- npm (Node Package Manager): This comes bundled with Node.js.
-
Clone the repository to your local machine:
git clone https://github.com/AKsHaT123456A/SubSpace.git cd SubSpace
-
Install the project dependencies:
npm install
-
Set up environment variables: Create a .env file in the project root and add the following:
PORT=3000
-
You can update the .env file with any additional configuration variables you may need. Start the application:
npm start
The application will start, and you can access it at http://localhost:3000.
This application provides the following main features:
Blog Statistics Endpoint:
- URL:
/api/blog-stats
- Method: GET
- Description: Fetches blog data from a third-party API, analyzes the data, and provides statistics.
- Response: JSON object containing blog statistics, including the total number of blogs, the title of the longest blog, the number of blogs with "privacy" in the title, and an array of unique blog titles.
Blog Search Endpoint:
- URL:
/api/blog-search
- Method: GET
- Description: Performs a case-insensitive search for blogs containing a specified query string in their titles.
- Query Parameter:
query
- The search query. - Response: JSON array containing matching blog titles.
The application includes comprehensive error handling for various scenarios, including invalid requests, internal server errors, and errors related to data retrieval and analysis. Errors are logged, and appropriate error responses are sent to clients to ensure a smooth user experience.
The application implements a caching mechanism using Lodash's memoize function. Cached results are stored for a certain period, reducing unnecessary API calls and computations. If the same requests are made within the caching period, the application returns cached results instead of re-fetching and re-analyzing the data.