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()
1. Callback function (Callback) 1. Concept 2. Example description Code description: Set a global variable A = 0, and then execute the WRITEFILE function (that is, write a file input01.txt). There is a...
async/await-1. Write an async/await function First quotenode-fetchLibrary, you can use await to request gracefully...
Foreword async-await ispromisewithgeneratoSyntactic sugar of r. Just to make our code more fluid, and of course enhance the readability of the code. simply put:async-await It i...
Introduction to async Async is placed in front of the function as a keyword, indicating that the function is an asynchronous function, meaning that the function execution does not block the execution ...
basic concepts The async and await seen command async / await syntactic sugar generator function, but there are some improvements to the generator function: generator is performed when the function re...
async is called the ultimate asynchronous solution, avoiding callback hell, and processing asynchronous operations in a synchronous way async and Generator asyncYesGeneratorThe syntax sugar of the two...
Synchronous function and asynchronous function The difference between the two Everyone can look at the link above, then I will describe the examples around you: The synchronization function is equival...
True to solve the problem of asynchronous callbacks, synchronous processes express asynchronous operation, essentially Async is Generator's syntax, async and await, used to optimize the use of Generat...
1.async function The async function does not return the return value. Default returns promise: {resolve} AWAIT is waiting is the result of promise execution success 2. The async function does not retu...
Asynchronous function --async / await The Async / AWAIT in ES8 is designed to solve the problem of using asynchronous structural organizational code. Async function The Async function returns a promis...