-
Notifications
You must be signed in to change notification settings - Fork 51
/
app.js
45 lines (32 loc) · 909 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Express from "express";
import dotenv from "dotenv";
import { connectDB } from "./config/connection.js";
import cors from "cors"
// models
import user from "./models/user.js";
import book from "./models/book.js";
import review from "./models/review.js";
// routes
import bookRoutes from "./routes/book.js";
import authRoutes from "./routes/auth.js";
import reviewRoutes from "./routes/review.js";
import notFoundHandler from "./middleware/not-found.js";
dotenv.config();
const app = Express();
app.use(cors());
// middleware
app.use(Express.json());
// routes
const baseURL = "/api/v1";
app.use(baseURL, authRoutes);
app.use(baseURL, bookRoutes);
app.use(baseURL, reviewRoutes);
// error handlers
app.use(notFoundHandler)
connectDB();
try {
const port = process.env.PORT;
app.listen(port, console.log(`Server running on port ${port}!`));
} catch (error) {
console.log(error);
}