File 如何在中使用通配符从具有Node.js的目录中读取文件

File 如何在中使用通配符从具有Node.js的目录中读取文件,file,wildcard,File,Wildcard,我需要从Node.js目录中读取文件,文件名都是一些.json如何在Node.js中的文件名部分使用通配符?您可以使用通配符文件名模式匹配 var glob = require("glob") // options is optional glob("DIR_PATH/*.json", options, function (er, files) { // files is an array of filenames. // er is an error object or null.

我需要从Node.js目录中读取文件,文件名都是一些.json如何在Node.js中的文件名部分使用通配符?

您可以使用通配符文件名模式匹配

var glob = require("glob")

// options is optional
glob("DIR_PATH/*.json", options, function (er, files) {
  // files is an array of filenames.
  // er is an error object or null.
})

非常感谢你的回答。我真的被困在想办法了。