Add intentional latency in express

2020-02-26 02:57发布

Im using express with node.js, and testing certain routes. I'm doing this tute at http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/

Im calling the http://localhost:3000/wines 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)

7条回答
劳资没心,怎么记你
2楼-- · 2020-02-26 03:46

Just call res.send inside of a setTimeout:

setTimeout((function() {res.send(items)}), 2000);
查看更多
登录 后发表回答