-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (25 loc) · 903 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
require('dotenv').config()
const express = require('express')
const app = express()
const cors = require('cors')
const mongoose = require('mongoose')
mongoose.connect("mongodb+srv://user1:[email protected]/**test**?retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
const db = mongoose.connection
db.on('error', (error) => console.error(error))
db.once('open', () => console.log('connekted :)'))
app.use(cors())
app.use(express.static('public'))
app.use(express.json())
app.use(express.urlencoded({extended: true}))
const usersRouter = require('./routes/api')
app.use('/api', usersRouter)
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html')
});
const listener = app.listen(process.env.PORT || 3000, () => {
console.log('Your app is listening on port ' + listener.address().port)
})