I have 2 requests 1 /Fibonacci (takes ~10sec) and 2 /hello (immediately)
when I try to run 2page consecutive 'message' is coming after Fibonacci I am using postman for both get-http://localhost:3001/fibonacci post-http://localhost:3001/hello
So my code running synchronous but I want it asynchronous, I tried promise and await but they both did not work for me.
const express = require('express')
const app = express()
const bigInt = require("big-integer");
const port = process.env.PORT || 3001
app.get('/fibonacci',async (req,res) => {
res.send(fibonacci(bigInt(700000)))
})
app.post('/hello',async (req, res) => {
res.send("message")
})
const fibonacci = (num) => {
var a = bigInt(1), b = bigInt(0), temp = bigInt
while (num > 0){
temp = a
a = (a.add(b))
b = temp
num= (num.add(-1))
}
return b;
}
app.listen(port, () => {
console.log('Server is up on port ' + port)
})
I expect the seen message immediately but it is coming after Fibonacci calculation.