I am abit confused by asynchronous mechanism in NodeJs. I a have router class below as you can see. I have two endpoint, When I have a request to endpoint '/a' it takes like 10 seconds to response. While this 10 seconds I can not have a request to endpoint '/b' although I used asynchronous code.
const express = require('express');
const fetch = require("node-fetch");
const router = express.Router();
router.route('/a')
.get(function (req, res) {
fetch(url)
.then(response => response.json())
.then(data => {
**SOME CODE BLOCKS, IT TAKES 10 Seconds.**
res.send(data)
}
);
});
router.route('/b')
.get(function (req, res) {
res.send("Hello");
});
module.exports = router;
Please somebody explain me this behavior.
Thanks.