Add intentional latency in express

Use as middleware, for all your requests

  app.use(function(req,res,next){setTimeout(next,1000)});

Just call res.send inside of a setTimeout:

setTimeout((() => {
  res.send(items)
}), 2000)

Try connect-pause module. It adds delay to all or only some routes in your app.


To apply it globaly on all requests you can use the following code:

app.use( ( req, res, next ) => {
    setTimeout(next, Math.floor( ( Math.random() * 2000 ) + 100 ) );
});

Time values are:

Max = 2000 (sort of.... min value is added so in reality its 2100)

Min = 100


just add a comment on top of the solution of @maggocnx : put this middleware early (before your route handler)

app.use(function(req,res,next){setTimeout(next,1000)});