This Node.js application uses TypeScript to interact with a weather API and fetch temperature data based on user-provided date and location parameters. It handles API rate limits, data formatting, and ensures data persistence using SQLite for caching.
- Node.js
- Docker
- SQLite
-
Clone the repository:
git clone <repository_url> cd weather-app
-
Install dependencies:
npm install
-
Build the application:
npm run build
-
Run the application:
npm start
-
Run tests:
npm test
To run the application using Docker:
-
Build the Docker image:
docker build -t weather-app .
-
Run the Docker container:
docker run -p 3000:3000 weather-app
GET /weather?city=<city>&date=<date>
- Parameters:
city
: The city for which to fetch the weather data.date
: The date for which to fetch the weather data (in ISO 8601 format).
- Example:
http://localhost:3000/weather?city=London&date=2024-07-20
- Parameters:
- SQLite: Used SQLite to cache weather data to avoid hitting the API rate limit. Cached data expires appropriately to ensure freshness.
- Initialization: The database and table are created if they do not exist.
- API Limits: Implemented robust error handling for API rate limits, random errors, and data format issues.
- Retries: Retries on transient errors to handle temporary issues with the API.
- Jest: Comprehensive tests for API integration, data conversion, caching mechanism, and error handling using Jest.
- Coverage: Ensures that the application works as expected and handles edge cases.
- The weather API endpoint and documentation are accurate and reliable.
- The cache expiration is handled within the scope of this task, and no external cache expiration policy is applied.
PORT
: The port on which the application will run (default is 3000).
- Ensure SQLite is installed and accessible in your environment.
- Ensure that the
.env
file is properly configured with the required environment variables if any.
{
"city": "London",
"date": "2024-07-20",
"temperatureCelsius": 20,
"temperatureFahrenheit": 68
}
weather-app/
├── src/
│ ├── index.ts
│ ├── server.ts
│ ├── weatherService.ts
│ ├── cache.ts
│ ├── types.ts
│ ├── utils.ts
├── tests/
│ ├── weatherService.test.ts
│ ├── cache.test.ts
├── .env
├── Dockerfile
├── jest.config.js
├── package.json
├── README.md
├── tsconfig.json