Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slowing down responses in Node.js

I'm using Express over Node.js and I'm currently writing loading views for my app (a screen that will show up when data is being fetched) but when I'm testing in local there are, obviously, no delays from the server and I can't see if the screens are working.

Is it possible to introduce a delay in Node.js for all responses without having to add a setTimeout for each response?

I tried slow-proxy, but it fails to load the absolute paths in the HTML (e.g. /img/item.png is mapped as such instead of /proxy/2000/img/item.png).

like image 845
JayC Avatar asked Feb 13 '23 15:02

JayC


1 Answers

In express/connect just put this above other middleware:

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

And a coffeescript version:

app.use (res,req,next)-> setTimeout(next,2000)
like image 153
Ilan Frumer Avatar answered Feb 16 '23 12:02

Ilan Frumer