-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (28 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
const express = require('express')
require('dotenv').config()
const mongoose = require('mongoose')
const DrinkRoutes = require('./routes/drink')
const cors = require('cors')
const app = express()
app.use(express.json())
app.use(cors())
app.set('view engine', 'ejs')
app.use('/uploads', express.static('uploads'))
app.use((req, res, next) => {
console.log(req.path, req.method)
next()
})
app.get('/', async (req, res) => {
res.render('index')
})
app.use('/api/drink', DrinkRoutes)
mongoose.connect(process.env.MONG_URI)
.then(() => {
app.listen(process.env.PORT || 5000, () => {
console.log('listening on port: ', process.env.PORT)
console.log('connected to mongoDB')
})
})
.catch((error) => {
console.log(error)
})