小编ant*_*zio的帖子

异步和递归目录扫描,用于 Nodejs 和 Expressjs 中的文件列表

在此Expressjs路由文件中,我尝试(递归地)获取./data目录内的所有 JSON 文件。

实际上,我可以在此处console.log文件,您可以看到A Mark,但我找不到在异步内容完成后将整组路径发送到视图的方法。

一些帮助将非常感激。

这是数据./数据结构:

--- dir1
    `-- json1.json
    `-- json2.json
--- dir2
    `-- json3.json
--- dir3
Run Code Online (Sandbox Code Playgroud)
const express = require('express'),
    router = express.Router(),
    fs = require('fs'),
    path = require('path')
    ;

let scan = function (directoryName = './data') {

    return new Promise((resolve, reject) => {

        fs.readdir(directoryName, function (err, files) {
            if (err) reject(err);

            files.map((currentValue, index, arr) => {
                let fullPath = path.join(directoryName, currentValue);

                fs.stat(fullPath, function (err, stat) { …
Run Code Online (Sandbox Code Playgroud)

asynchronous fs node.js express es6-promise

3
推荐指数
1
解决办法
5171
查看次数

标签 统计

asynchronous ×1

es6-promise ×1

express ×1

fs ×1

node.js ×1