-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
39 lines (33 loc) · 876 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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const projectsRoutes = require("./routes/projectRoute");
const userRoutes = require("./routes/userRoute");
// express app
const app = express();
// port
const port = process.env.PORT || 4000;
// middlewares
app.use(cors());
app.use(express.json());
app.use((req, res, next) => {
console.log(req.path, req.method);
next();
});
// routes
app.use("/api/projects", projectsRoutes);
app.use("/api/user", userRoutes);
// connecting to the database(mongodb)
mongoose.set("strictQuery", false);
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
// listening request
app.listen(port, () => {
console.log(`Connected to Mongo & Listening on port ${port}`);
});
})
.catch((error) => {
console.log(error);
});