In my case, a write stream could not be created without first making the directory. Using fs.mkDir() or fs.mkdirSync() to create the directory in advance fixes the issue.
fs.mkDir()
fs.mkdirSync()