When using nodejs to crawl web page content, if there are too many requests, sometimes an exception will be thrown, prompting errors such as too many connections. Does nodejs have such keywords or class libraries for thread locking? Or how to handle it better? First, thank you!
typecho2017-06-27 09:21:30
nodejs does not have functions such as sleep.
I usually use event to match
const EventEmitter = require('events').EventEmitter;
const ee = new EventEmitter();
ee.on('next',(数据)=>{
// 爬网站
});
// 每秒执行一次
setInterval(()=>ee.emit('next','数据'),1000);