我需要使用 Node.js 从目录中读取文件,文件名都是 .json 如何在 Node.js 中对文件名部分使用通配符?
您可以使用globnpm来使用通配符文件名模式匹配
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.
})
Run Code Online (Sandbox Code Playgroud)