DEV Community

Discussion on: Designing a better architecture for a Node.js API

Collapse
 
adrianhelvik profile image
Adrian

Bug: Failing to unlink a file will cause an unhandled rejection.

await new Promise((resolve, reject) => {
  fs.unlink(path, err => {
    if (err) reject(err)
    else resolve()
  })
})

Now the unlinking is awaited as well.

Additionally you don't need the Connection class. Just write the code at the top level.

Collapse
 
pacheco profile image
Thiago Pacheco

Thank you for reporting that Adrian, actually this part wasn't supposed to be in the code.
I was going to add a file upload functionality too but I realized it would make this post very long and I forgot to remove it all.
And thank you for the solution too, I am going to add this in the next functionalities :)