-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (28 loc) · 864 Bytes
/
server.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
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import morgan from "morgan";
import cors from "cors";
import "express-async-errors";
import AuthRoute from "./routes/AuthRoute.js";
const app = express();
app.use(express.json());
// CORS Policy
app.use(cors());
// inport the database connection
import connectDB from "./config/connectdb.js";
// middleware
import errorHandlerMiddleware from "./middlewares/error-handler.js";
// this is for the finding the error
if (process.env.NODE_ENV !== "production") {
app.use(morgan("dev"));
}
const DATABASE_URL = process.env.DATABASE_URL;
const port = process.env.PORT;
app.use("/api/v1/auth", AuthRoute);
// Apply the middleware
app.use(errorHandlerMiddleware);
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
connectDB(DATABASE_URL);
});