-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
57 lines (46 loc) · 921 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
let express = require('express');
let app = express();
app.get('/', function (req, res) {
let obj = {
endpoints: [
"/hangar",
"/ping",
"/current-date",
"/fibo/:n",
]
};
res.send(obj);
});
app.get('/hangar', function (req, res) {
res.send("Hello World");
});
app.get('/ping', function (req, res) {
res.send("pong");
});
app.get('/current-date', function (req, res) {
let obj = {
name: "current",
value: new Date()
};
res.send(obj);
});
app.get('/fibo/:n', function (req, res) {
let obj = {
name: "fibo",
value: fibo(req.params.n)
};
res.send(obj);
});
let server = app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
function fibo(n) { // 1
if (n < 1)
return 0;
else if (n < 2)
return 1;
else
return fibo(n - 2) + fibo(n - 1);
}
module.exports.server = server
module.exports.fibo = fibo