I have this file named index.js
:
const express = require('express')
const app = express()
const port = 3000
app.get('/home', (req, res) => {
res.send('Hello World!')
})
app.get('/route1', (req, res) => {
var num = 0;
for(var i=0; i<1000000; i++) {
num = num+1;
console.log(num);
}
res.send('This is Route1 '+ num)
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
I first call the endpoint /route1
and then immediately the endpoint /home
. The /route1
has for loop
and takes some time to finish and then /home
runs and finishes. My question is while app was busy processing /route1
, how was the request to /home
handled, given node js is single threaded?