view raw
Akshat Akshat - 9 months ago 37
Node.js Question

Add intentional latency in express

Im using express with node.js, and testing certain routes. I'm doing this tute at

Im calling the

via ajax (the content doesn't matter). But I want to test latency. Can I do something like make express respond after 2 seconds? (I want to simulate the ajax loader and I'm running on localhost so my latency is pretty much nil)


Just call res.send inside of a setTimeout:

setTimeout((function() {res.send(items)}), 2000);