-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (25 loc) · 799 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require("express");
const mongoose = require("mongoose");
const { scheduleCryptoDataFetch } = require("./services/cronJobs");
const cryptoRoutes = require("./routes/cryptoRoutes");
require("dotenv").config();
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(express.json());
// MongoDB connection
mongoose
.connect(process.env.MONGO_URI)
.then(() => console.log("MongoDB connected"))
.catch((err) => console.error("MongoDB connection error:", err));
// Routes
app.get("/", (req, res) => {
res.send("Hello World");
});
app.use("/api", cryptoRoutes);
// Start the cron job for background data fetching
scheduleCryptoDataFetch();
// Start server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});