-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 808 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
require("dotenv").config();
const express = require("express");
const cors=require('cors')
const mongoose = require("mongoose");
const projectRoutes = require("./routes/projectRoutes");
const userRoutes=require('./routes/userRoutes')
const app = express();
//port
const port = process.env.PORT || 4000;
//midlewares
app.use(express.json());
app.use(cors())
app.use((req, res, next) => {
console.log(req.method, req.url);
next();
});
//routes
app.use("/api/projects", projectRoutes);
app.use("/api/user",userRoutes)
//mongodb
mongoose.set('strictQuery', true);
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
//listen for server
app.listen(port, () => {
console.log(`connect to mongo listening on port ${port}`);
});
})
.catch((err) => {
console.log(err);
});