Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从全局节点js返回一个数组_Node.js_Glob_Fs_Getfiles - Fatal编程技术网

Node.js 从全局节点js返回一个数组

Node.js 从全局节点js返回一个数组,node.js,glob,fs,getfiles,Node.js,Glob,Fs,Getfiles,问题 我在这里使用答案 然而,当我把它赋给一个常量时,我试图返回目录以便在数组中使用它们,我查阅了globs文档中的asnwer,但是没有成功的结果,我尝试使用glob.end()和console.log下面的folds变量,我可以看到所有可用方法的列表,并且我尝试过使用其中一些方法,但没有成功。有人知道如何像下面的代码示例中那样返回数组吗?谢谢大家! const glob = require('glob'); const src = 'assets'; function getFile

问题

我在这里使用答案 然而,当我把它赋给一个常量时,我试图返回目录以便在数组中使用它们,我查阅了globs文档中的asnwer,但是没有成功的结果,我尝试使用glob.end()和console.log下面的folds变量,我可以看到所有可用方法的列表,并且我尝试过使用其中一些方法,但没有成功。有人知道如何像下面的代码示例中那样返回数组吗?谢谢大家!

 const glob = require('glob');
 const src = 'assets';


function getFiles(err, res){
  if (err) {
   console.log('Error', err);
  } else {
  return res
  }
}

let folds =  glob(src + '/**/*', getFiles);

我也有同样的问题

glob()

改用
glob.sync()
(其中
.sync
表示同步)

例如:

const files=glob.sync(src+'/***');

我也有同样的问题

glob()

改用
glob.sync()
(其中
.sync
表示同步)

例如:

const files=glob.sync(src+'/***');

哪里是
src
集,您的回调函数也没有收到
err
res
@lawrencerone编辑错误哪里是
src
集,您的回调函数也没有收到
err
res
@lawrencerone编辑错误