I have the following code on a server:
let tmpFileName;
// GET
app.get('/clicked', async (req, res) => {
    let nullOutput = writeTmpFile("hello, world!");
    await deleteTmpFile();
    console.log("Hurray, finished!");
    res.send({result:nullOutput});
})
function writeTmpFile(content){
    tmpFileName = "tmp" + Math.random().toString() + "tsl";
    return new Promise(resolve => {
        fs.writeFile(tmpFileName, content, function (err) {
            if (err) throw err;
            console.log('Temp file creation successful.');
        });
    })
}
function deleteTmpFile(spec){
    return new Promise(resolve => {
        fs.unlink(tmpFileName, function (err) {
            if (err) throw err;
            console.log('Temp file deletion successful.');
        });
    })
}
However, in my console output, I only get
Temp file creation successful.
Temp file deletion successful.
However, if I delete await deleteTempFile(), then Hurray, finished! shows up on the console.
And more generally, how do I debug these patterns of problems? Why is this happening?
 
     
     
    