Node A method in an object called another method of that object

the code is as follows

const File = require("../lib/file").File
const path = require("path")
const fs = require("fs")

let handleFile = {
    // 
    create (file) {
        return File.create(file)
    },
    //  id 
    getFileById (id) {
        return File
            .findOne({ _id: id })
            // .addCreatedAt()
            .exec()
    },
}
//  id 
handleFile.deleteFileById = function async (id) {
    let fileObject = await handleFile.getFileById(id)
    fs.unlink(path.join("../uploads",fileObject.filename))
    return File
        .remove({ _id: id })
        .exec()
}
// 
// fileOperate.getFilePath = function async (id) {
//     let fileObject = await file_operate.getFileById(id)
//     return path.join("../uploads",fileObject.filename)
// }
module.exports = handleFile

screenshots of the error report are as follows

clipboard.png

nodejs version 8.9.3 async/await can be used normally

Mar.04,2021

async is there a mistake?


async should be placed in front of function.


//  id 
handleFile.deleteFileById = async function (id) {
    let fileObject = await handleFile.getFileById(id)
    fs.unlink(path.join('../uploads',fileObject.filename))
    return File
        .remove({ _id: id })
        .exec()
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3c48b-4361a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3c48b-4361a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?