Node.Js fs module in Multer for automatic folder creation
Monib Bormon
React js | Next js | front end | Node js | Javascript | MERN Stack Developer
Hey Guys ??,
So let's make our code easier to run and functional for practical use cases. When we use multer npm package to upload multipart form data in our express app. In that situation, we have to create a folder like uploads in our working directory before uploading any file. If we don't create a folder before uploading then it shows like this below:-
To Solve this issue we can use Node JS build-in file system ( fs ) module. Simply
add this code in multer.diskStorage where we set the destination of our files.
Here, if we don't have a folder on our server, it will automatically create one for our files.
I hope you learn from these small tips.
Cheers,
Monib Bormon ??