-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 1.03 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
const express = require('express')
const mongoose = require('mongoose')
const users = require('./routes/api/users');
const bodyparser = require('body-parser');
const tasks = require('./routes/api/tasks')
const masterclasses = require('./routes/api/masterclasses')
const app = express()
app.use(express.json())
app.use(bodyparser.json());
const db = require('./config/keys').mongoURI
mongoose
.connect(db)
.then(() => console.log('Connected to MongoDB'))
.catch(err => console.log(err))
app.get('/', (req, res) => {
res.send(`<h1>Lirten Hub</h1>
<a href="/api/tasks">Tasks</a>
<a href="/api/users">Users</a>
<a href="/api/masterclasses">Masterclasses</a>
`);
})
app.use('/api/tasks', tasks)
app.use('/api/users', users)
app.use('/api/masterclasses', masterclasses)
app.use((req, res) => {
res.status(404).send({err: 'We can not find what you are looking for'});
})
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`Server up and running on port ${port}`))