-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 993 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
require("dotenv").config();
require("express-async-errors");
const morgan = require("morgan");
const cookieParser = require("cookie-parser");
//express
const express = require("express");
const app = express();
// database
const connectDB = require("./config/connect");
//middleware
const errorHandlerMiddleware = require("./middleware/error-handler");
const notFoundMiddleware = require("./middleware/not-found");
const authRouter = require("./routes/authRouter");
const PORT = process.env.PORT || 5000;
app.use(morgan("tiny"));
app.use(express.json());
app.use(cookieParser(process.env.JWT_SECRET));
app.get("", (req, res) => {
res.send(`e-commerce api`);
});
app.use("/api/v1/auth", authRouter);
app.use(notFoundMiddleware);
app.use(errorHandlerMiddleware);
const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(PORT, () => console.log(`Server is listening on ${PORT}...`));
} catch (error) {
console.log(error);
}
};
start();