Calling asynchronous functions like fs.unlink and fs.rmdir in Node starts a task. You pass them a function as an argument – a callback – that gets called when that task completes. The callback has an argument that tells you whether the operation completed successfully.
You’re already making use of this partially by only calling fs.rmdir when fs.unlink has completed. Now you need to say what to do when fs.unlink has completed (even if it’s nothing), and start checking for errors.
An example of something you can do when there’s an error is throw that error, which prints it and exits the process.
fs.unlink('stuff/writeMe.txt', (err) => {
if (err) throw err;
fs.rmdir('stuff', (err) => {
if (err) throw err;
});
});