https://github.com/saurabhkumardev/crypto-tracker-backend
https://github.com/saurabhkumardev/crypto-tracker-backend
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/saurabhkumardev/crypto-tracker-backend
- Owner: SaurabhKumarDev
- Created: 2025-07-17T16:40:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-20T18:26:06.000Z (12 months ago)
- Last Synced: 2025-07-20T20:21:52.364Z (12 months ago)
- Language: JavaScript
- Size: 180 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# ๐ช CryptoTracker Backend
This is the **backend API** for the CryptoTracker application. It fetches, stores, and serves cryptocurrency data using the **CoinGecko API**, **MongoDB**, and **Express.js**. A cron job runs every hour to update current and historical coin data automatically.
---
## ๐ Tech Stack
- **Node.js**
- **Express.js**
- **MongoDB + Mongoose**
- **CoinGecko API**
- **Node-Cron** (for scheduled data fetching)
- **dotenv** (for environment variable management)
---
## ๐ฆ Project Structure
```
crypto-tracker-backend/
โโโ models/
โ โโโ Coin.js
โโโ routes/
โ โโโ coins.js
โโโ services/
โ โโโ coinGeckoService.js
โ โโโ cronService.js
โโโ .env
โโโ index.js
โโโ package.json
โโโ package-lock.js
โโโ readme.md
```
---
## โ๏ธ Setup & Installation
### 1. Clone the repository
```bash
git clone https://github.com/saurabhkumardev/crypto-tracker-backend.git
cd crypto-tracker-backend
```
### 2. Install dependencies
```bash
npm install
```
### 3. Configure environment variables
- Create a .env file in the root directory:
```env
MONGODB_URI=mongodb://localhost:27017/cryptotracker
PORT=5000
CLIENT_URL=http://localhost:3000
NODE_ENV=development
```
### 4. Run the server
```bash
npm run dev
```
---
- Server will run at: http://localhost:5000
---
## โฐ Cron Job โ Hourly Coin Data Sync
- A cron job runs every hour to:
- Fetch top 10 coin data from the CoinGecko API.
- Update the CurrentCoin collection using upsert.
- Insert a snapshot into the HistoryCoin collection.
- Delete historical data older than 30 days.
### Cron Job Code:
- Located at: services/cronService.js
```
cron.schedule("0 * * * *", () => {
this.updateCoinData()
}, { timezone: "UTC" })
```
- Also runs immediately after server starts (with 5-second delay).
## ๐ก External API Used
- CoinGecko API
- Base URL: https://api.coingecko.com/api/v3
- Endpoint Used: /coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10&page=1
## ๐ MongoDB Collections
๐ธ CurrentCoin
Stores latest data of top 10 coins (upserted each hour).
๐ธ HistoryCoin
Stores hourly snapshots of coin data for tracking trends and charts.
๐ API Endpoints
- All routes are prefixed with /api
```
Method Endpoint Description
GET /api/coins Get current coin data
GET /api/coins/history Get historical data by coinId and days
```
# ๐ Deployment Links
๐ Backend API: https://your-backend.onrender.com/api
๐ Frontend App: https://your-frontend.vercel.app
## ๐งช Testing the API
- You can test the endpoints using:
- Postman
- Browser (for GET)
Example:
- curl http://localhost:5000/api/coins
## ๐ Contact
- ๐ผ linkedin.com/in/saurabhkumardev
- ๐ง saurabhkumarmehto@gmail.com
## DB (History crypto)

## Cron job (Code)
