从node.js + express4 写一个自己的博客网站教程中写代码,发现获取所有文件夹下的文件,最终结果如何在外面得到呢??return 返回的不是getBlogList的返回值吧?
js
function getBlogList(blogDir) { fs.readdir(blogDir, function (err, files) { var blogList = []; if (files && files.length) { files.forEach(function (filename) { //split file name and generate url... //... //create a blogItem { title: blogTitle, url: blogUrl } blogList.push(blogItem); }); } return blogList; }); }
刚接触node,疑惑很久,请各位赐教~谢谢
You can choose from the following methods. The first is the most traditional, the fourth is the most elegant (but can’t be used now), and the third is second only to the fourth in elegance. The method during the transition period, The second one is more widely used and comes in many variations.
The one upstairs is the correct answer. Add a simple and crude method