-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 788 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
const express = require("express");
const cors = require("cors");
require("dotenv").config();
const projectRouter = require("./routes/projectRoute");
const userRouter = require("./routes/userRoute");
const mongoose = require("mongoose");
// express app
const app = express();
// port
const port = process.env.PORT || 4000;
// middleware
app.use(cors());
app.use(express.json());
app.use((req, res, next) => {
console.log(req.url, req.method);
next();
});
// routes
app.use("/api/projects/", projectRouter);
app.use("/api/user/", userRouter);
// mongo
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
// listening for reqiest
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
})
.catch((err) => {
console.log(err);
});