Skip to content

Instantly share code, notes, and snippets.

@mjzone
Created June 12, 2021 16:21
Show Gist options
  • Save mjzone/eed44e30e522d11c247f79af355c8ea3 to your computer and use it in GitHub Desktop.
Save mjzone/eed44e30e522d11c247f79af355c8ea3 to your computer and use it in GitHub Desktop.
const express = require("express");
const app = express();
// Health check endpoint
app.get("/health", (req, res) => {
res.status(200);
res.send("healthy");
});
// Calculating the fibonacci value
let fib = (n) => {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
app.get("/generate/:number", (req, res) => {
let output = 0;
try {
const number = parseInt(req.params.number);
if (number) {
output = fib(number);
}
} catch (e) {
res.send("Error");
}
res.json({ output });
});
app.listen(80, () => {
console.log("App listening on port 80!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment