Node.js async/await~ example of deleting files

1) Delete files like synchronous writing

var util = require("util");
var fs = require("fs");
var unlink = util.promisify(fs.unlink);

async function f(fileNameArr) {
    for(var i = 0; i < fileNameArr.length; i++){
        await unlink(fileNameArr[i]);
    }

}

//
f(["./1.txt", "2.txt", "3.txt"]);

 

Intelligent Recommendation

node.js async / await handle exceptions?

First, I just console, I do not deal with. Second, the agreed rules...

SQLite Node.js of the async / await encapsulation

Each SQLite function for synchronization, and can await interface. Note: You need SQLite for Node module and Node.js 8.0+, and support for async / await. SQLite most commonly used as a local storage u...

Callback/Async Await/Promisify in Node.js

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...

More Recommendation

The concept of async await in Python (example)

Code example Example of the original author  ...

Vue Async / AWAIT asynchronous example

Vue Async / AWAIT asynchronous example 1.async / await scene This is a scheme for synchronous thinking to solve the asynchronous problem, when the current end interface calls need to wait until the in...

Simple example of Async AWAIT / PROMISE

1. Simple use of Async AWAIT / PROMISE; 2, other documents: JS prototype chain async await/promise...

ASYNC and AWAIT read multiple files

The existing MD files are as follows: part1.md part2.md Fish encounter. Md Demand: Read the contents of the above three files and output. First, review how many files are implemented by reviewing how ...

ASYNC and AWAIT combine reading files

Previous article has been introduced, usepromiseThe way of reading files, greatly reduces the useTune hellDifficulties. BelowasyncandawaitCombined with the read file instance, you can achieve the same...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top