-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (27 loc) · 766 Bytes
/
app.js
File metadata and controls
35 lines (27 loc) · 766 Bytes
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
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const port = 8080
app.use(bodyParser.json())
app.get('/health', (req, res) => {
res.header({ "System-Health": true })
res.sendStatus(204)
})
app.get("/", (req, res, next) => {
res.json("You're Connected to our API!")
res.sendStatus(204)
})
const fibonacci = n => {
if (n <= 1) {
return n
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
app.post('/fibonacci', (req, res) => {
const fibIndex = req.body.index
res.status(202).json({ index: fibIndex, result: "calculating..." })
console.log("Fibonacci number:", fibonacci(fibIndex))
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})