-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
40 lines (31 loc) · 851 Bytes
/
app.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
const express = require('express')
const connectToDatabase = require('./database/dbConfig')
const user = require('./routes/user')
const tutorial = require('./routes/tutorial')
const errorMiddleware = require('./middlewares/error')
const app = express()
//express middleware
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.get('/', (req, res) => {
res.status(400).send('Api working')
})
app.use('/user', user)
app.use('/tutorial', tutorial)
app.use('*', (req, res) => {
res.status(404).json({
success: false,
errors: [
{
msg: 'Route not found',
},
],
})
})
app.use(errorMiddleware)
const PORT = process.env.PORT || 3000
connectToDatabase().then(_ => {
app.listen(PORT, _ => {
console.log(`Server started on port ${PORT}`)
})
})