const fs = require('fs');
const path = require('path');
function getFile() {
return new Promise((resolve, reject) => {
const filePath = path.resolve(path.join(__dirname, '../public/images'));
fs.readdir(filePath, (err, files) => {
var fileArr = [];
files.forEach(filename => {
fileArr.push('/static/images/' + filename);
resolve(fileArr)
});
})
});
}
async function getImagesPath() {
let result = await getFile();
return result;
}
function insertDbData(){
getImagesPath().then(res => {
console.log(res)
})
}
insertDbData()
async和await改写node.js的读取文件函数
最新推荐文章于 2023-01-05 10:43:47 发布