In Node, the way possibly-asynchronous callbacks are typically structured is that the first argument is an error, OR the second argument is the success value. For example, you'll very often see patterns like this:
callSomeAPI((error, result) => {
if (error) {
// There was an error, do something with it
handleError(error);
} else {
// Success
handleResults(result);
}
});
This filename
callback is doing the same sort of thing. If you implement some custom logic and want to indicate that the process failed, pass the first argument containing the reason to the callback:
callback('Desired filename contains invalid characters');
Otherwise, leave the first argument nullish:
callback(null, 'fileNameHere');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…