Nodejs is asynchronous, which is a bit more concurrent;
For example, if you want to access multiple URLs, you can access concurrent accesses at the same time, which is very good for multi-threaded download.
However, if the subsequent program requires the results of the previous program to continue, this problem occurs in the Multi-concurrency environment.
Async can solve this problem.
It should be noted that async can control the serial execution of functions, but the function interface must be set and callback is executed at last!
Var urlcontent = "http://bbs.chinagame.me/topic/1/1#1"; var r = require ('request'); var subject, content; var async = require ('async'); function a (callback) {req = r (urlcontent, function (a, B, c) {var body = c; var regex =/<title> (. *?) <\/Title>/gim; var title = regex.exe c (body); subject = title [1]; var regex1 =/itemprop = "text"> (.*?) <\/Div>/gim; var con = regex1.exec (body); content = con [1]; callback (null, 'two ');});} function B (callback) {console. log (subject, content); callback (null, 'B');} async. series ([a, B]);