Reduce the number of code if possible when creating a folder
The built in file system package (fs) provides you with a commands to create directories.

fs.mkdirSync(path[, options]) for synchronous

fs.mkdir(path[, options], callback) for asynchronous

According to their documentation, you can add an option for recursively creating a folder. It also notes 

"Calling fs.mkdir() when path is a directory that exists results in an error only when recursive is false."

With this information, you should be able to force it to always create the folder using only this logic:

const fs = require('fs')
fs.mkdir( directory, { recursive: true }, (err) =&gt; {
  if (err) throw err;
});