forked from achref-bououn/BackEnd_Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (36 loc) · 1.12 KB
/
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
/*
The backend has the following structure
Every request will follow the following path:
Index.js -> Routes -> Controller -> Service -> Model
After the update on the mode is done, the controller will respond with res.send()
To add a new route, follow the following structure
app.use("api/[ENDPOINT]", NAME_OF_THE_ROUTE)
*/
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
require("dotenv").config();
const app = express();
const userRoute = require("./routes/user.route.js");
mongoose
.connect("mongodb://localhost:27017/basic", {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
})
.then(() => {
console.log("connected to mongodb");
})
.catch((err) => {
console.log("failed to connect to MongoDB", err);
});
app.use(express.urlencoded());
app.use(express.json());
app.use(cors());
//list all of your routes here
app.use("/api/user", userRoute);
const PORT = process.env.PORT || 3030;
app.listen(PORT, () => {
console.log("app connected on: " + PORT);
});