forked from GeekyCats/Krishi-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 895 Bytes
/
index.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
32
33
34
import express from "express";
import cors from "cors";
import helmet from "helmet";
import mongoose from "mongoose";
import { PORT, MONGO_URI } from "./util/secret.js";
import userRoutes from "./routes/user.js";
import weatherRoutes from "./routes/weatherForecast.js";
import newsRoutes from "./routes/news.js";
const app = express();
app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.get("/", (req, res) => {
res.send("WELCOME TO KRISHI BACKEND!");
});
app.use("/account", userRoutes);
app.use("/weather", weatherRoutes);
app.use("/news", newsRoutes);
mongoose
.connect(MONGO_URI)
.then(() => {
console.log("Connected to MongoDB");
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
})
.catch((error) => {
console.log("Error connecting to MongoDB: ", error);
});