-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (41 loc) · 933 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import express from "express";
import dotenv from "dotenv";
import mongoose from "mongoose";
import cors from "cors";
import morgan from "morgan";
const app = express();
dotenv.config();
/** Middlewares */
app.use(express.json());
const corsConfig = {
credentials: true,
origin: true
};
app.use(cors(corsConfig));
app.use(morgan("tiny"));
const port = process.env.PORT || 8800;
const connect = () => {
mongoose.set("strictQuery", true);
mongoose
.connect(process.env.MONGO_URL)
.then(() => {
console.log("MongoDB connected");
})
.catch((err) => {
console.log(err);
});
};
app.use((err, req, res, next) => {
const status = err.status || 500;
const message = err.message || "Something went wrong";
return res.status(status).json({
success: false,
status,
message,
});
});
app.use(express.json());
app.listen(port, () => {
console.log("Connected");
connect();
});