I am having a code.
try{ var Storage = multer.diskStorage({ destination: function (req, file, callback) { fs.mkdirSync('/home/data/' + file.originalname, { recursive: true }, (error) => { if (error) { } else { alert('Directory created'); console.log('Your directory is made!'); } ........ }catch(e){ console.log(e); } Even I have a try catch, my program is giving a exception when the directory is already present. I am not getting why ..the node is crashing and not procedding. can you please let me know if I am missing anything
Error I am getting is
fs.js:885 return binding.mkdir(pathModule._makeLong(path), ^ Error: EEXIST: file already exists, mkdir '/home/data/dd_dd' at Object.fs.mkdirSync (fs.js:885:18) at DiskStorage.destination [as getDestination] (/home/server.js:16:7) at DiskStorage._handleFile (/home/nodejsapplication/node_modules/multer/storage/disk.js:31:8) at /home/node_modules/multer/lib/make-middleware.js:144:17 at allowAll (/home/node_modules/multer/index.js:8:3) at wrappedFileFilter (/home/node_modules/multer/index.js:44:7) at Busboy.<anonymous> (/home/node_modules/multer/lib/make-middleware.js:114:7) at emitMany (events.js:147:13) at Busboy.emit (events.js:224:7)