Is there any way that I can make express server handle several GET requests in parallel?
Consider this example:
server.js
var express = require('express')
var app = express();
app.get('/test01', function (req, res, next) {
for (i = 0; i < 1000000000; i++) {
var temp = i*i;
}
res.end('{"success" : "test01", "status" : 200}');
});
app.get('/test02', function (req, res, next) {
for (i = 0; i < 1; i++) {
var temp = i*i;
}
res.end('{"success" : "test02", "status" : 200}');
});
app.listen(8081, function () {
console.log("server listening at %s:%s", this.address().address, this.address().port)
})
client.js
var request = require("request");
request("http://127.0.0.1:8081/test01", function(error, response, body) {
console.log(body);
});
request("http://127.0.0.1:8081/test02", function(error, response, body) {
console.log(body);
});
After running the client.js, the output is:
{"success" : "test01", "status" : 200}
{"success" : "test02", "status" : 200}
which means that the second request will have to wait for the first request to be finished.
What do I need to change in server.js in order to make both of the requests run in parallel and making "test01" non blocking service and finishing test02 before test01?
I don't want to change anything in client.js and I can't control the timing of the calling of the services. e.g test01 may be call 3 times sequentially and than test02 may be called.