This Node.js Express application serves as a backend for fetching and caching contest data from a third-party API. The fetched data is stored in a Redis cache, and the backend offers an efficient way to retrieve this data through API requests while minimizing the load on the external API.
- Data Caching: The application fetches fresh contest data from the Clist API and stores it in a Redis cache. This helps reduce the number of requests made to the external API and enhances response times.
- Scheduled Data Refresh: A cron job is set up to periodically refresh the contest data at fixed intervals (every 30 minutes by default). This ensures that the cached data remains up-to-date with the latest information from the external API.
- Middleware for Cache Check: A middleware is implemented to check the Redis cache before making a request to the external API. If the requested data is available in the cache, it is served directly, minimizing the need to make repeated calls to the external API.
Before running the application, make sure you have the following:
- Node.js installed
- Redis server running locally or on a remote server
- API key for the Clist API
-
Clone the repository:
git clone https://github.com/yourusername/contest-data-backend.git cd contest-data-backend
-
Install dependencies:
npm install
-
Create a
.env
file in the project root and provide the necessary environment variables:CLIST_API_USERNAME=your_username CLIST_API_KEY=your_key PORT=3000
-
Run the application:
npm start
The server will start on the specified port (default is 3000).
-
Access the API:
The API endpoint is
http://localhost:3000
. You can make GET requests to this endpoint to retrieve contest data. The middleware will check the Redis cache before fetching fresh data from the Clist API.
Feel free to contribute to the development of this project by opening issues or submitting pull requests. Make sure to follow the contributing guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Node.js
- Express.js
- Redis
- axios
- node-cron
- dotenv
Thank you for using and contributing to the Contest Data Backend!