JavaScript Promises Tutorial - Section 8: Course Project
Build a production-ready application that fetches, processes, and aggregates data from multiple APIs with advanced Promise patterns.
Create a robust data aggregation system that demonstrates:
data-aggregator/
├── src/
│ ├── api/
│ │ ├── client.js # Base API client
│ │ ├── weatherAPI.js # Weather data source
│ │ ├── newsAPI.js # News data source
│ │ └── stocksAPI.js # Stock data source
│ │
│ ├── utils/
│ │ ├── retry.js # Retry logic
│ │ ├── timeout.js # Timeout wrapper
│ │ ├── cache.js # Caching layer
│ │ ├── rateLimiter.js # Rate limiting
│ │ └── logger.js # Logging utility
│ │
│ ├── aggregator/
│ │ ├── index.js # Main aggregator
│ │ ├── transformer.js # Data transformation
│ │ └── validator.js # Data validation
│ │
│ └── index.js # Entry point
│
├── tests/
│ ├── unit/
│ │ ├── retry.test.js
│ │ ├── cache.test.js
│ │ └── rateLimiter.test.js
│ │
│ └── integration/
│ └── aggregator.test.js
│
├── config/
│ └── default.js # Configuration
│
├── package.json
└── README.md
/api/weather?city=London/api/news?category=tech/api/stocks?symbol=AAPL// src/aggregator/index.js
class DataAggregator {
constructor(apis, utils) {
this.apis = apis;
this.utils = utils;
}
async fetchAll() {
try {
const [weather, news, stocks] = await Promise.all([
this.utils.retry(() => this.apis.weather.get()),
this.utils.retry(() => this.apis.news.get()),
this.utils.retry(() => this.apis.stocks.get())
]);
return {
weather,
news,
stocks,
timestamp: new Date().toISOString()
};
} catch (error) {
console.error('Aggregation failed:', error);
throw error;
}
}
async fetchWithCache() {
const cacheKey = 'dashboard-data';
const cached = await this.utils.cache.get(cacheKey);
if (cached) {
return cached;
}
const data = await this.fetchAll();
await this.utils.cache.set(cacheKey, data, 300); // 5 min TTL
return data;
}
}
export default DataAggregator;
Start building your project! Use the lessons learned throughout this course to create a robust, production-ready data aggregator. Good luck! 🚀