This project is a Node.js application that fetches cryptocurrency data for Bitcoin, Matic, and Ethereum, stores it in MongoDB, and provides APIs to retrieve the latest data and calculate price deviations.
- Node.js: JavaScript runtime.
- Express.js: Web framework.
- MongoDB: Database.
- CoinGecko API: To fetch cryptocurrency data.
- Node.js (version 14.x or higher).
- MongoDB (local or MongoDB Atlas).
- CoinGecko API key (optional).
- Clone the repository:
git clone https://github.com/yourusername/crypto-data-fetcher.git cd crypto-data-fetcher - Install Dependencies:
npm install
- Set up MongoDB connection:
MONGODB_URI=mongodb://localhost:27017/crypto_data
- Set up CoinGecko API key: COINGECKO_API_KEY=
- Start the server: npm start
- Fetch Cryptocurrency Data The background job runs every 2 hours, fetching data from the CoinGecko API and saving it to MongoDB.
- Get Latest Data
GET /stats?coin=<coin_name>
- Calculate Standard Deviation
GET /stats?coin=bitcoin
Background Job Runs every 2 hours using node-cron to fetch data for Bitcoin, Matic, and Ethereum from the CoinGecko API.
const cron = require('node-cron');
cron.schedule('0 */2 * * *', () => {
fetchData();
});