Create a request waiting-list on NodeJs

718 Views Asked by At

I'd like to build a NodeJS server that responds to requests just one at the time.

Basically: by doing fetch('<domain>/request/<id> I want that untill the client received the data the other requests are queued. Is it possible?

1

There are 1 best solutions below

0
On BEST ANSWER

An npm module like express-queue could work.

var express = require('express');
var queue = require('express-queue');
var app = express();
app.use(queue({
    activeLimit: 1
}));

app.use("*", function(req, res, next) {
    setTimeout(function() {
        res.send("OK");
    }, 2000);
});
app.listen(3000);