-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (30 loc) · 820 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
import express from "express";
import dotenv from "dotenv";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import cors from "cors";
// routes
import userRoutes from "./routes/userRoute.js";
dotenv.config();
const app = express();
// middlewares
// general middlewares
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
// route middlewares
app.use("/api/users", userRoutes);
const PORT = process.env.PORT || 5000;
(async () => {
try {
await mongoose.connect(process.env.MONGOOSE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
app.listen(PORT, () => {
console.log(`server running on PORT=${PORT}`);
});
} catch (err) {
console.log("error while starting", err);
}
})();