-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 1.04 KB
/
index.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 bodyParser = require('body-parser')
const helmet = require('helmet')
const cors = require('cors')
const app = express()
const port = 8000 // set the default PORT
// -----------------------------------------------------------------------------
// EXPRESS PLUGINS
// Use body-parser into express, so we can get request body (req.body)
app.use(bodyParser.json())
app.use(helmet())
app.use(cors())
// -----------------------------------------------------------------------------
// EXPRESS ROUTES/ENDPOINTS
const root = require('./middlewares/index')
const users = require('./middlewares/users')
app.get('/', root.hello)
app.get('/users', users.getUsers)
app.post('/users', users.createNewUser)
app.delete('/users', users.deleteAllUsers)
app.delete('/users/:id', users.deleteOneUserById)
app.put('/users/:id', users.updateOneUserById)
// -----------------------------------------------------------------------------
// RUN EXPRESS
app.listen(port, () => {
console.log(`Express app is listening on localhost:${port}`)
})