-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (42 loc) · 1.4 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const cors = require('cors')
const mongoose = require('mongoose')
require('dotenv').config()
const cookieParser = require("cookie-parser")
const errorhandler = require('./middlewares/errorMiddleware')
const app = express();
app.use(cors({
origin: 'http://localhost:3000', // Specify the allowed origin
credentials: true // Enable Access-Control-Allow-Credentials
}))
app.use(express.json())
app.use(cookieParser())
app.use(express.urlencoded({extended: false}))
const PORT = process.env.PORT || 9000;
const userRoutes = require("./routers/userRoutes")
app.use("/api/user", userRoutes)
const adminRoutes = require("./routers/adminRoutes")
app.use("/api/admin", adminRoutes)
const managerRoutes = require("./routers/managerRoutes")
app.use("/api/manager", managerRoutes)
app.use(errorhandler)
// Define a simple route
app.get("/",(req, res)=>{
//local date get from ntp and convert into local string
const date = new Date().toISOString()
res.send(`Server is running on ${date}`)
})
// Start the server
mongoose.connect(process.env.MONGODB_URL,
{
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(()=>{
app.listen(PORT,()=>{
console.log('MONGODB connection established')
console.log(`Server is running on port ${PORT}`)
})
}).catch((error)=>{
console.log('Error', error)
})