-
Notifications
You must be signed in to change notification settings - Fork 133
/
server.js
46 lines (37 loc) · 952 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
40
41
42
43
44
45
46
const express = require('express')
const morgan = require('morgan')
const connectDB = require('./config/db')
const bodyParser = require('body-parser')
const cors = require('cors')
// Config dotev
require('dotenv').config({
path: './config/config.env'
})
const app = express()
// Connect to database
connectDB();
// body parser
app.use(bodyParser.json())
// Load routes
const authRouter = require('./routes/auth.route')
const userRouter = require('./routes/user.route')
// Dev Logginf Middleware
if (process.env.NODE_ENV === 'development') {
app.use(cors({
origin: process.env.CLIENT_URL
}))
app.use(morgan('dev'))
}
// Use Routes
app.use('/api', authRouter)
app.use('/api', userRouter)
app.use((req, res) => {
res.status(404).json({
success: false,
msg: "Page not founded"
})
})
const PORT = process.env.PORT || 5000
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});