-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (40 loc) · 1.35 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
54
const express = require('express')
const app = express();
require('dotenv').config();
const mongoose = require('mongoose')
const cors = require('cors')
const PORT = process.env.PORT || 4000
const languages = require('./controllers/languages')
const comments = require('./controllers/comments')
//=============================Middleware
app.use(cors());
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
const monogURI = process.env.DATABASE_URL;
const db = mongoose.connection;
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
});
db.on('error', (err) => console.log(err.message + ' is Mongodb not running?'));
db.on('connected', () => console.log('mongo connected: ', "get 2 work"));
db.on("disconnected", () => console.log('mongo disconnected'));
db.on( 'open', () =>{
console.log("connection made")
})
//=============================Routes
const langRouter = require('./controllers/languages')
app.use('/languages', langRouter)
const comRouter = require('./controllers/comments')
app.use('/comments', comRouter)
app.get('/', (req,res) => {
res.send('does it work??')
})
app.get('/', (req,res) => {
res.redirect('/languages')
})
//=============================Start Server
app.listen(PORT, () => {
console.log('Devography listening on port 4k')
})