{"id":1187,"date":"2022-08-30T11:27:22","date_gmt":"2022-08-30T11:27:22","guid":{"rendered":"https:\/\/www.workfall.com\/learning\/blog\/?p=1187"},"modified":"2025-09-26T09:51:59","modified_gmt":"2025-09-26T09:51:59","slug":"how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js","status":"publish","type":"post","link":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/","title":{"rendered":"How to upload single or multiple images to a local directory with Multer in Node.js?"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>\n<p><img src=\"https:\/\/lh6.googleusercontent.com\/lXtYZforCe5iorghwBmTmF7mW7mHFO0E94FQrXEyujcmwxvjfYzR17kyDRbCaSoLvslMfi2y4AUB7zDeh4OO2VEP8qEOeNB6RUC5aUCTJhoHQWFo7m-1TeHfO8zh32lhUHsmsQPhSIF2feKTTIZlNbrRRJ_lyvdoePtWEnwcF4YonkiPFGf1NfUhOw\" style=\"width: 1600px;\"><\/p>\n\n\n\n<p class=\"has-text-align-justify\">The most fundamental operation of any application is a file upload. While images can be uploaded on the front end, they must be received via an API and database on the backend. You can set up file and image uploads in one place using Multer and Express, a Node.js framework. In this blog, we will demonstrate how to upload single or multiple images to a local directory with Multer in Node.js.<\/p>\n\n\n\n<h2>What is Multer?<\/h2>\n\n\n\n<p class=\"has-text-align-justify\"><a href=\"https:\/\/www.npmjs.com\/package\/multer\">Multer<\/a> is a node.js middleware for handling multipart\/form-data that is primarily used for file uploading, according to the documentation. For maximum efficiency, it is written on top of the busboy.<\/p>\n\n\n\n<h2>Hands-on<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">In this hands-on, we will see how we can make use of a package &#8211; Multer to upload single or multiple images. We will begin with creating a new directory and installing express in that directory. Post that we will install multer and verify its installation in the package files. Then we will import the required packages, run the server, and test if the application is running as expected. Once that is done, we will then create a new folder to store the uploaded images in it.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Post that, we will write a function to create image storage for the images that are to be uploaded. Then we will create a function to let us be able to upload images using the multer package. We will then create a route for us to hit the URL and test the package for uploading the image. Navigating to the postman application, we will hit the URL and check if the image is uploaded onto the local machine. We will then create a route for uploading multiple images and navigating to the postman application, we will configure the Body parameters and hit the new URL to upload multiple images, and finally test the same by checking if the images are uploaded in the created folder.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/wcD_tw3vvZ1IH3CCHeX-ll8DetQ0M1Pwk4QYUkUdjUFbAwDIW0w4LQZZ1uXkahIObjJ7TLvoet72IW92WiRiP4D2qDqlnaERSITUhrxd83vRMAgZh1FKGw_8H2kkbosvVcpDPwv2Uy4XoBPInJviOEzc319ehBryyWVzuefrzryZYoAQAMLtScEl-A\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\"><strong>Note:<\/strong> Please ensure that Node.js is properly installed onto the local machine or else it might display multiple errors while following the process.<\/p>\n\n\n\n<p>Create a new directory on your local machine.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/2U8rtjzrK7tL4554E5ejEGMfHAZLzVWT0RX9p2ySy8cG4ltA8k_-TCLkuG4qtbm6ili8vjZwvzcpar2SQETFMpUlOPGTuD-arQ6gAgHvfF-dI6oxgLzy4-E_yfktjMHjPdYNyyhF3T21Cv-zdzVg5U_9fcXJO72fK0cXFhNR1MZAZeB2cZAGpOXq\" alt=\"\"\/><\/figure>\n\n\n\n<p>Open the newly created directory into a code editor.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/QQnOh2uFOOHh5Jeaqwyg05WNV-6NEtfDbRXwzRPrEry6YLJZazvtpv9EaFBP49-Yswz6tknNaILM4aX6XDfezYAulo7eQJd-9rC12J22FKog2XuXdZFsS-5bFcPtTTyV6ZlaY-0JGQpeALNgzKv6gu36JAjMHvIBiInVq-kXEk51YHyXOtIJ24dR\" alt=\"\"\/><\/figure>\n\n\n\n<p>Right-click in the left navigation pane and click on New file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/iS7l9MW1MZIwgB9tUo0eiMBB1NGfmz45iQK3isPvwiSl07_J2rRDlCerV7BFMHjy1q3ydZBLBdfX-xl1Pqzp8WDm05dZ1us-GXGo7x_OwmJK3Yxz4RPy2PTGbK_5LHADD6MIt0WV5RcxtY8WQ8BvtImtV3YVY6QnBXRNgLFCNgsXp56Hx8p0sgxr\" alt=\"\"\/><\/figure>\n\n\n\n<p>Create a new file with the name <em>package.json<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/H3hgOpk247B8VHHi-doG4fz6FmB347PzJcTqKcRUbUdiaOzlGoIhFE1moqhYM6P2bHfhMLHjI1WTB_FtebXvhF5BcUwzxYCqciwNaGiWxtQmxow7BsyCr6Y5ohoq548mwMlXEwaNRPcfwK6E6h5bekgwF0EqHpVw39iDgwt3trt0WWTRAPLon2HS\" alt=\"\"\/><\/figure>\n\n\n\n<p>Right-click in the newly created directory and click on Git Bash Here.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/REl2Yg2wFJtCjI1U3OccGBr4ioVdwvWvp2bEnHzrcKP3TJdyKi54cKwiYo5Dka4MmzI5HpfeTbIUjDPH3-OlrEaYzyHSZQRQGOxyUzbquEOzcVLNJkTVjs8HZlpPHdZ3tN2nrwWZay_6P6k1bD8Eh__zMOzR1g1VAMPSo2Q-zwtC52rLL1jdbbzg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Run the command: <code>npm init<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/qRopBsHkLwkviHKJPNRujuzxDwyE94dAYs9dYcg_IVcav3yx75r2RnI7aIhSdev5oKgKXuj6ZNgqzaRhh1WBfMdgsR_PfN6WANCU3bc_YOZDI_bLAU4eqWjJjbwXkBpAc1pHpcEF73BZng1uM4zrJ2jZ8xibZgyE4lLlO2-scJBI6_oGJU8HM9Wv\" alt=\"\"\/><\/figure>\n\n\n\n<p>Press yes after selecting the default values.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/OeUkcJJtk3hlIRd3gk7pahcJ3LXRxArhjfVOozIAPOZVDZlsN_UcUHOyznZtIac_rt8jo4X4NCTHhx70z4PuMr8jMID2DFCZW265ema9nwtMaMUSl5skg6BpFp4O5oRp0v6G7TnEOIcoeTKCYn7MD0GUyuzfQtNNLkEKk8u047BScv2t4rKngpxf\" alt=\"\"\/><\/figure>\n\n\n\n<p>Verify the configuration setup in the <em>package.json<\/em> file created above.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/ZKIALt746o2N2Du9hzuNCM8deuLXHw9Jy8D6F5h3vxFzs4cJagoJlLPi610DzJvgmQVd1UyF-TIBBPrT6Thmz965LezNriB2MUDmC6fgr7uIDJX-8yHuYquTS2BoL0Q1GabLB2z1nU7_pdadh0jEhx0lYwmIFf-nfxPIxUQ03-fy7MPD4YeXbU60\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Now, we need to install express. To do so, use the following command:<\/p>\n\n\n\n<p><code>npm install express --save<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/2jIGlkN7cBs2cwB02mEZD52o9dVnaQF9XcIfhhhb3-q-jwJ2FZfgWruIHqwfS6lynTtpzO1mVt14NhMjlql5XB8ur12JrvfBvF8oXUvr6htQLgFvR9EZ8-2IE9MaQ756bamLj8sxNTa1RwCW_ZOWCoMTmVdC5K0U-OyXF7BTvsqYOPpjRpGZ-qBP\" alt=\"\"\/><\/figure>\n\n\n\n<p>Post that, we need to install a multer package. To do so, use the following command:<\/p>\n\n\n\n<p><code>npm install --save multer<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/cGJIBNg_-OW8ViG9i1Xp9uP-bKSkhWdv4eiGWFktdq5738XKZ_6C2_v_NxKrZIgKzzts4lYvF5fhvbZanbl_B6_EhFz6nlEfhGfteSlNu0tS1Y-10pJeQTXiYp2LO5BxVcNkcoSpY2AS5fdkAGnkueRSXXsOgFqrEVEzLsPeAvfuvSa-sFiFineS\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Verify the package installations by navigating to the <em>package.json<\/em> file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/KTuOhyiOlfwgoLHFXRS2sO_LIZoxP0KHM2mOqz35I8dpdEET4GpXbG_KzAggQXKPCmGLsXnZV3Svc3vxoIxqiM9h4zjz6dEuzbUDcEhf74JdvKHYyrwoyg_Sq7kYrwdNHbx6jfsaBJbnKP3czElKBokMEsQOdwY5Lsls6Wlb1X3-sOkb9rVgg9Nk\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>A new <em>package-lock.json<\/em> file will be created in the directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/smZfDcDiv5nISo9HPOYYHK-W8oa2-UQnO-HGYNNb5JWaRwJPN9ls2Sa3gjvMMtwL4Ige5qYoZzIPfWtmqH4SGihjp1SGjziadt-2dEXTr9TmftjI2miLw8oN660x5xWkph46X-Wqz7WPkjPYLheVObR98adbd-fqjJADV1V8gQS1tDLE9h3YfcTM\" alt=\"\"\/><\/figure>\n\n\n\n<p>Create a new file with the name <em>app.js<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/D1vI2ejbAchddJNlhrRlKTo-lCySKaXzAKGU_4lAtTK4TEjR0VVFmyu81eARXpzRZpyT7OFENxQn5C3FaK6VA_k_WDPzvorrlolfMxvHkLl10-kjpxqC7aTMimdGr-tJ-XmpcKj_NLrPktHE3u0ndQau7AJIVECo9eZe4bvHww0EFlrITx5FzRhm\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>In the <em>app.js file<\/em>, import the express package using the below snippets code.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/8NE4rciCruzCbp8EsR6-d5tuuFu9Ky6GIE4Vfn51XsH-VWm1S5oq3Uj_L986g4x1hVfBuvlrREeAI0aZ4-v9YerBzQz-9Ijj3fSwkYA8EBdcKOIEYtqJMzjp6-Ukfp-jm_aq09mQdTvU-WnMy9e_f5_UUq-M0-rBxOBCF0JQyyQqICtdStg1kjYH\" alt=\"\"\/><\/figure>\n\n\n\n<p>Define a port number using the below code on which our application will run.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/uNphrkl7Eg_a2T1OSGJAmgbX89tgakBKwGDAojawQNWhZM92PQZiXAsx3BzgCfXjUe0O3MoqeaOpTDb_xS9vCmf4tZ6AHJHACNRCo7es8uRBZlf7Wt3yKnUTJaHBy_MXFRK-hN5PQJqnXPhF9TgT-RvERfq4l5qsxjxL9iwKgDkRsuF-VtdB3Pf9\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, configure a route to display a message on running the server.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/XO0jbpe3pnbxPU3MIoXfJ1kMYLbaNHX5REH7v5Zu4MDPozGNdeviBMnvb7xXFBhHhc1iqwYPng4-MTApDiFLKPV8kNR2KsTFlGiDE2-_omOgLMmcWz_DQtp2IZFioy4e-h5Xw8yu2_o3rUVcip-epcbWG6I_-24WKMfIieg3GXt5aU5_GzxrXwfR\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, start the server using the command:<\/p>\n\n\n\n<p><code>node app.js<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/WI6LAmLUVC50ZSJnxzuxtU2i3v-yC0BUlDJ8QH-r4_EO48gTRsS6OTVTlIz3gg4ugYNpbWVZ1LoCAloHTeFTlqEQvKmQqhgRStAoPr_VZSKBKQByEzOB8v2rY8xHPbiaflFC6kDBGUrsGXxQO3Og2aszlKiVuWkDLJBPSwcSlEnNoyZ5uXwdgYO1\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">On any of the browsers, use the link <a href=\"http:\/\/www.localhost:3000\">http:\/\/www.localhost:3000<\/a> and hit enter. On success, you will see the image as entered above.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/GoHSiDl4c7I3beohKonk4uZGZU7Na56mixickJ42KpjttzLNhLrBxXcRrVJqACrcjFanldJ_XtcY2ScikJD5icHvU4zrvHCJGZErqPWVSr4lLWIkhtYzykKXMNB5bx-UX_5frOSKjoi21_Ug0l0e8IIVZKmm7CYoGvBnnYhBNA11a51hulqKR0tH\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, import the multer package using the below code.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/J0elTujQYzc9w-OEHuco_BsDhI-fIMO6pPvsFJxhvORwQorcsLDg35b9sG4j1HEYlmtMh7SpqoELV8FdgzMBz_7vC95GSTmHrHwIvWpL78tTT6YBmOi-X9t2Isg_DmbmU8CGtg1npSVKfpolPV1itdLyX8LuEFAiGPLBhyRKEK1Q_udFyHvaHDzT\" alt=\"\"\/><\/figure>\n\n\n\n<p>The final import code looks as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/qru8zjwQ_T4VwR2pGI5gkzz-f6UnMxMcQ1Podkr84PXrSxSknOHZjiCX2xDjPQ5xUBEx01xy1UeuBffhM-bVy3033ZsZfvcdLfCPj5R5Rg8hQZ1b_Bv8iLYiZznrs_-HMimlfpS0-wdAgFWjid7R-21Z-X12ui6Rvc3mHDvhlqzkn5nEZvolN4K0\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Now, create a new folder with the name images in the directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/4HrSnp6Pti5mDXRGOfkoUJqufZspYe37u5NmT4p_R15iLUTSOrQnIN5ZJS4zFHz3pdgHgXeFFr6oZPOxCzDZeLykGevQ6ly3bCHObj5BtV52Pr-TzStDYT5zuKMGeSICTdeNiO1287Ye1lc9GFXg3cBNUDsrXI4ciR7NlbzdariDqgePOHWvVTyX\" alt=\"\"\/><\/figure>\n\n\n\n<p>Then we will create a variable function to define the storage location for all the image files.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/Oqu4og2yfwNsRAiaI4tDlm5Dr-gyMGfCBBPAw5AO_a5pEkyqjgaL3YEB3HjnnANbg2fSw_88hxCH_7z-crOqAalY0Iy76IlfonpVRoEQCqAtEkqmAcKmpLIgh-gtI1XxOnH2JBTzupmV_8dFJ26DEYCBDoxnhPvOBgmcSLqqZew6hbFtrHeVKjy6\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Moving further, we will create a variable function for using Multer to limit the file size thereby attaching the file storage and catching errors if any.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/M7Hp8W7lEoja9SHlTYmI5A4xsUGdA3BhpiJS01p56s1sAwOu1hINaCoj0QlNiERKJ1qRHSLUkI-Ue5UCJk14wkXaFohCK4B2gel8vBnJSOaFzetpJW0CguyTr254eSNW74B96kSQuhTvqeGM1Mi44xLrpJxnoPRApOc1OgxvFezPxXlWvW2RcTLk\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">We will then create a route for uploading the image using which when we hit the URL with the file, the file can be uploaded to the directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/taW14xQwXeeCAYaBxoBouwjM1EpvasNn0rKnFL-TybOg3UN1x9dqZ-Z-NmAzBq2dUukTf0rxf9s6PpsOhqWYBXtEmmn2-gJM6tkrOyB6mOdIz1nxR2nOOcC65b9px-QuKTkfb_9Mz7eVAFuwCUoqI-VtG5M_RQbLqpPdopyt0G82ioy-cVk88zdK\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Now, open postman. We will be using postman to hit the URL. Click on the + sign.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/8bftmM8ofcQc9si-UJv1UX2H88iKVjyzOky_p9F-PYLu94_Aq5Z6HiC1eL28WHb2ljMk7ZrptZLcaDj_DNDyubS3gGpFQmydAc7IbC9Muy5b4IbqpfNLN9G5jWizx66s6_hfKM5LDD_1n7hja7R9nD8fnTMO4Twe5mt8PKTPH16XMGeC8o8n7yVS\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Add the URL as <em>localhost:3000\/uploadImage<\/em> and change the request type to POST.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/f-3gNzLwadm56xIPm8sGfamTklUMholzeUbnK2kyOLiYKf_qrE2WuCWgz5IvURKrcj5S_fZmCl3orbgjOIzmxO0lMn-eyvXQw0E6xJJgyxz78qmkiFY4iYVTiJtx6DzTbA-c7rkA6diIZI3ll0QURDYshlBlGj_3h6m5J9fVMH7cPFWLs6_P5ixv\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Then, click on Body.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/znprO3jYZF9PNvuwhMTTBr7KPyh2icxNR5Zt7c8HJITQXYJh5LUzgMk-FRDzpcBu5EUauK8e2R7XK2HGf6pZ7an9QsJxXW99AeRF9LLr1uxg8p45nWe_SqpOD5llXrA9An9Vhmoi9H7pKJTNo2AUXo6Y2qCoDXhu8KyTUNQarkSS4N1z6lTZrfOE\" alt=\"\"\/><\/figure>\n\n\n\n<p>Select the type as File.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/bDG6YLC9xRZnxwcLPCgyUXyHfgZWlXMUEViaRwo49fKtVEDcmPz9gmuGnC2nfz0JBqND9NLnkUyLm_0MounGelW_kry5XD-BaeQDGlR_L5EuPEjP78GGbr2Va007IEuYnKcYJWzcgN9_Qytyy3TWona8xft24ZmRR2ojSiRCKLR3a7c32QjYCRjK\" alt=\"\"\/><\/figure>\n\n\n\n<p>In the keys, add an image. Select the image by selecting the file. Click on Send.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/mRsQlljrfhQIVuwHKZ9oDHF4RsW25nwFj-a3cX6wKfI9x28ax8i1mb8Khkyd4xQkQxHNngXNvndJv1GzMe3FV374w9Z9KP75NiYB7UrQ48QVzMLWnwde8Uq8Xdpazbm3PYqq3vaC3VunwuSaHbjWGjiiUyR5vEGpGoA9IXdTlZER5mEF3rCy8Sqg\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, you will see the object output as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/KGSoNLRfhV7J7aXPEvMLuMrMK2HWYx0u0EpEPMxYvJnJoEHrdkg-PvLBcCxMCDsaFjyK-mNWm83E9OE6cUzwlnq6zYXU2YPhU2_4T2eVhJT66FI1lTV17ivJ2SKIt2fNWc-c4FaQ6CnavVGOUHmWjBpG7FL8eM4CEvM7Hr-2zRYJxwUwRaff60EY\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Now, navigate back to the directory and check the images folder. You&#8217;ll see the image uploaded to the folder that you created.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/B-HEU9sYg-e244loHGqCzStSMpkhiFXH_U37o238RbVSPBGKs-xQh3-ANtx7zBx21bKixn7pc_SuDIaQTOMCs9J68SpGG8gSuelqnNUKr1fiRiVLSX7cY2bxmBJpv0T2_rGzK4bPGBzJaJKCQ5aexbuh4mHKG4irONySFdnrY4ERZIsPE-aKSYLV\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, let&#8217;s add a route to upload multiple images. Use the below code for the same.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/FBgomhfW1UQr2vScUhRjst8w5Kbe8Dho9nq0_ynvG2b7Dx7UkQKZxkcR7SQobJHoakGZZtLYLqk0lQgScxVKjQBvyozfbHe5tFdfvAKzSBCFxnhs_2dbQNfTharSs3tDHy0LqrPEeq1E5zv0gg6_jGYcK6WCnsRRt24Yz_JrpTaz31xS1Ex3yNKE\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Now, open postman. Add multiple image files in the Body. Under keys, add the key name as images and select the image files for the same. Click on Send.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/zYjlQkFrqFYtb5GY_keMl5ND1mEzM1jTXjP4IttUdhCv4U0gHaTcyKKfRlFMyFJgUa33-G180QISXj5njUoRPazUKIsNIQGr-e261n7T70G7_AotZ6XksBrLyvn42jGCs8M1aiFBRhQzpitM3w2a9jjGyTtgPFeLl6TE58-a6jrBkXm-q8p7W43o\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, you will see the following object output as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/eDD-almvn6RNKK839TxWn346fEUhAWvGYCE9AGcz7lBQcSkx_iHcBBf2POCzMTOtevGb-5Btlwhn_9Wn_11eEQi5e0aBKIcrW9ZXECtYEwgXeggP6uEyoFm34L9eo-K1THbXd-vgh-qNMldQARtM0XHD9cx7w-l5tvW5zmAryQgFRpG1pxF2pbEf\" alt=\"How to upload single or multiple images to a local directory with Multer in Node.js?\"\/><\/figure>\n\n\n\n<p>Navigate back to the images folder and you will see the uploaded images as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/GXgf-orHC5VFXsLxMlcKCQKbRKDKI__klUAXzFW2UhWEtx51x1-fBt_Ftdn9yeJmQjuDDjHWMmJjIW-1incMk95YNlv1TdUkWzuf1xmsyMimzgmvB033xa5jcHAIz6oaV0LJFDg8G6domWHY5Os_c5RUnqcyVbLBKcvPZk5T4xyRzVkJsvWsMRXu\" alt=\"\"\/><\/figure>\n\n\n\n<h2>Conclusion<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">In this hands-on, we saw how we could make use of a package &#8211; Multer to upload single or multiple images. We began with creating a new directory and installing express in that directory. Post that we installed multer and verified its installations in the package files. Then imported the required packages, executed the server, and tested if the application was running as expected. We then created a new folder to store the uploaded images in it. Post that, we wrote a function to create image storage for the images that were to be uploaded. Then we created a function to let us be able to upload images using the multer package. We then created a route for us to hit the URL and test the package for uploading the image. Navigating to the postman application, we hit the URL and checked if the image was uploaded onto the local machine. We created a route for uploading multiple images and navigating to the postman application, we configured the Body parameters and hit the new URL to upload multiple images, and finally tested the same by checking if the images were uploaded in the created folder. We will come up with more such use cases in our upcoming blogs.<\/p>\n\n\n\n<p><strong>Meanwhile\u2026<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-justify\">If you are an aspiring Backend developer and want to explore more about the above topics, here are a few of our blogs for your reference:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-create-and-delete-email-templates-on-amazon-ses-using-node-js-and-postman-api\/\">How to create and delete Email Templates on Amazon SES using Node.js and Postman API?<\/a><\/li><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-send-customized-emails-by-integrating-sendgrid-with-a-node-js-application\/\">How to send customized emails by integrating SendGrid with a Node.js application?<\/a><\/li><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-connect-to-mysql-database-and-run-crud-operations-in-node-js\/\">How to connect to MySQL database and run CRUD operations in Node.js?<\/a><\/li><\/ul>\n\n\n\n<p>Stay tuned to get all the updates about our upcoming blogs on the cloud and the latest technologies.<\/p>\n\n\n\n<p><strong>Keep Exploring -&gt; Keep Learning -&gt; Keep Mastering&nbsp;<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-justify\">At <a href=\"https:\/\/www.workfall.com\/\">Workfall<\/a>, we strive to provide the best tech and pay opportunities to kickass coders around the world. If you\u2019re looking to work with global clients, build cutting-edge products and make big bucks doing so, give it a shot at <a href=\"https:\/\/www.workfall.com\/partner\/\">workfall.com\/partner<\/a> today!<\/p>\n\n\n\n<p><\/p>\n\n\n<style type=\"text\/css\"><\/style><section id='' \n                class='helpie-faq accordions faq-toggle open-first groupSettings-527__enabled' \n                data-collection='' \n                data-pagination='0' \n                data-search='0' \n                data-pagination-enabled='0'\n                role='region'\n                aria-label='FAQ Section'\n                aria-live='polite'><h3 class=\"collection-title\">Frequently Asked Questions:<\/h3><article class=\"accordion \"><div class='helpie-faq-row'><div class='helpie-faq-col helpie-faq-col-12' ><ul><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-3016\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-3016\"\r\n                data-id=\"post-3016\" \r\n                data-item=\"hfaq-post-3016\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. What is Multer, and why is it used for file\/image uploads?<\/div><\/div><div id=\"accordion-content-post-3016\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-3016\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><b>A: <\/b><span style=\"font-weight: 400\">Multer is a middleware for handling <\/span><span style=\"font-weight: 400\">multipart\/form-data<\/span><span style=\"font-weight: 400\">, which is primarily used for uploading files. It processes incoming file data (from client form submissions) and makes file metadata and content accessible in <\/span><span style=\"font-weight: 400\">req.file<\/span><span style=\"font-weight: 400\"> or <\/span><span style=\"font-weight: 400\">req.files<\/span><span style=\"font-weight: 400\">. It simplifies saving uploads either to memory, local disk, or custom storage engines.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-3017\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-3017\"\r\n                data-id=\"post-3017\" \r\n                data-item=\"hfaq-post-3017\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. How do I configure Multer to accept single vs multiple image uploads?<\/div><\/div><div id=\"accordion-content-post-3017\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-3017\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><b>Answer:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">For <\/span><b>single<\/b><span style=\"font-weight: 400\"> file: use <\/span><span style=\"font-weight: 400\">upload.single(&#8216;fieldName&#8217;)<\/span><span style=\"font-weight: 400\"> \u2014 then the uploaded file is in <\/span><span style=\"font-weight: 400\">req.file<\/span><span style=\"font-weight: 400\">.<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">For <\/span><b>multiple<\/b><span style=\"font-weight: 400\"> files (same field): use <\/span><span style=\"font-weight: 400\">upload.array(&#8216;fieldName&#8217;, maxCount)<\/span><span style=\"font-weight: 400\"> \u2014 <\/span><span style=\"font-weight: 400\">req.files<\/span><span style=\"font-weight: 400\"> is an array of file objects.<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">For multiple fields with potentially multiple files each: use <\/span><span style=\"font-weight: 400\">upload.fields([{ name: &#8216;field1&#8217;, maxCount: n1 }, { name: &#8216;field2&#8217;, maxCount: n2 }])<\/span><span style=\"font-weight: 400\">.<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">You define a storage engine (e.g. <\/span><span style=\"font-weight: 400\">diskStorage<\/span><span style=\"font-weight: 400\">) with destination and filename functions, possibly filter file types, set file size limits, etc.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-3018\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-3018\"\r\n                data-id=\"post-3018\" \r\n                data-item=\"hfaq-post-3018\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. How do I store the uploaded images in a local directory?<\/div><\/div><div id=\"accordion-content-post-3018\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-3018\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\">\u00a0<\/span><b>A:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400\"> Use Multer\u2019s <\/span><span style=\"font-weight: 400\">diskStorage<\/span><span style=\"font-weight: 400\"> option:<\/span><\/p>\n<p><span style=\"font-weight: 400\">const storage = multer.diskStorage({<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0destination: (req, file, cb) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0cb(null, &#8216;uploads\/&#8217;); \/\/ local folder<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0filename: (req, file, cb) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0const unique = Date.now() + &#8216;-&#8216; + file.originalname;<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0cb(null, unique);<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400\">});<\/span><\/p>\n<p><span style=\"font-weight: 400\">const upload = multer({ storage });<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Then apply the upload middleware to your route. After a successful upload, you can (in the route handler) respond with file paths or metadata to the client.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-3019\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-3019\"\r\n                data-id=\"post-3019\" \r\n                data-item=\"hfaq-post-3019\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. How do I validate file types, restrict to images only, and prevent malicious uploads?<\/div><\/div><div id=\"accordion-content-post-3019\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-3019\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><b>A:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400\"> Use a <\/span><span style=\"font-weight: 400\">fileFilter<\/span><span style=\"font-weight: 400\"> function in Multer config:<\/span><\/p>\n<p><span style=\"font-weight: 400\">fileFilter: (req, file, cb) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0const allowed = \/jpeg|jpg|png|gif\/;<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0const ext = path.extname(file.originalname).toLowerCase();<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0if (allowed.test(ext) &amp;&amp; allowed.test(file.mimetype)) {<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0cb(null, true);<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0} else {<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0cb(new Error(&#8216;Only image files allowed&#8217;));<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Also set <\/span><span style=\"font-weight: 400\">limits: { fileSize: maxBytes }<\/span><span style=\"font-weight: 400\"> to prevent overly large uploads. Sanitize filenames, avoid path traversal attacks, and store uploads in non-executable directories. After upload, verify the file&#8217;s MIME type via inspecting magic bytes if needed.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-3020\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-3020\"\r\n                data-id=\"post-3020\" \r\n                data-item=\"hfaq-post-3020\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. What error handling should I incorporate and how do I serve the uploaded images?<\/div><\/div><div id=\"accordion-content-post-3020\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-3020\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\">\u00a0<\/span><b>Answer:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">Wrap upload middleware in try\/catch or pass errors to Express\u2019s error handler (e.g. handle <\/span><span style=\"font-weight: 400\">MulterError<\/span><span style=\"font-weight: 400\">)<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">Return meaningful error responses for file size exceed, invalid type, or missing files<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">On success, respond with the URL or path to the stored image(s)<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">To serve images, use Express static middleware (e.g. <\/span><span style=\"font-weight: 400\">app.use(&#8216;\/uploads&#8217;, express.static(&#8216;uploads&#8217;))<\/span><span style=\"font-weight: 400\">) so clients can fetch by URL (e.g. <\/span><span style=\"font-weight: 400\">\/uploads\/filename.jpg<\/span><span style=\"font-weight: 400\">)<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">Optionally, delete unused\/old files, validate file existence before serving, and add caching headers<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/div><\/li><\/ul><\/div><\/div><\/article><\/section>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">7<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span> The most fundamental operation of any application is a file upload. While images can be uploaded on the front end, they must be received via an API and database on the backend. You can set up file and image uploads in one place using Multer and Express, a Node.js framework. In this blog, we will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1188,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[288],"tags":[85,27,251,301,334,244,335,265,250,6],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog<\/title>\n<meta name=\"description\" content=\"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog\" \/>\n<meta property=\"og:description\" content=\"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/\" \/>\n<meta property=\"og:site_name\" content=\"The Workfall Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/workfall\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-30T11:27:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-26T09:51:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@workfall\" \/>\n<meta name=\"twitter:site\" content=\"@workfall\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Workfall\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\",\"name\":\"Workfall - Hire #Kickass Coders On Demand\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/workfall\/\",\"https:\/\/www.linkedin.com\/company\/workfall\/\",\"https:\/\/facebook.com\/workfall\",\"https:\/\/twitter.com\/workfall\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400\",\"contentUrl\":\"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400\",\"width\":400,\"height\":400,\"caption\":\"Workfall - Hire #Kickass Coders On Demand\"},\"image\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#website\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/\",\"name\":\"The Workfall Blog\",\"description\":\"#Tech #Remote #Jobs\",\"publisher\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learning.workfall.com\/learning\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png\",\"contentUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png\",\"width\":1200,\"height\":628,\"caption\":\"Multer in Node.js\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/\",\"name\":\"How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog\",\"isPartOf\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage\"},\"datePublished\":\"2022-08-30T11:27:22+00:00\",\"dateModified\":\"2025-09-26T09:51:59+00:00\",\"description\":\"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!\",\"breadcrumb\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learning.workfall.com\/learning\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to upload single or multiple images to a local directory with Multer in Node.js?\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage\"},\"author\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a\"},\"headline\":\"How to upload single or multiple images to a local directory with Multer in Node.js?\",\"datePublished\":\"2022-08-30T11:27:22+00:00\",\"dateModified\":\"2025-09-26T09:51:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage\"},\"wordCount\":1193,\"publisher\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png\",\"keywords\":[\"api\",\"Database\",\"express\",\"expressjs\",\"images\",\"javaScript\",\"multer\",\"node\",\"nodeJS\",\"workfall\"],\"articleSection\":[\"Backend Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a\",\"name\":\"Workfall\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png\",\"contentUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png\",\"caption\":\"Workfall\"},\"sameAs\":[\"https:\/\/www.workfall.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog","description":"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/","og_locale":"en_US","og_type":"article","og_title":"How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog","og_description":"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!","og_url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/","og_site_name":"The Workfall Blog","article_publisher":"https:\/\/facebook.com\/workfall","article_published_time":"2022-08-30T11:27:22+00:00","article_modified_time":"2025-09-26T09:51:59+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@workfall","twitter_site":"@workfall","twitter_misc":{"Written by":"Workfall","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization","name":"Workfall - Hire #Kickass Coders On Demand","url":"https:\/\/learning.workfall.com\/learning\/blog\/","sameAs":["https:\/\/www.instagram.com\/workfall\/","https:\/\/www.linkedin.com\/company\/workfall\/","https:\/\/facebook.com\/workfall","https:\/\/twitter.com\/workfall"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400","contentUrl":"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400","width":400,"height":400,"caption":"Workfall - Hire #Kickass Coders On Demand"},"image":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#website","url":"https:\/\/learning.workfall.com\/learning\/blog\/","name":"The Workfall Blog","description":"#Tech #Remote #Jobs","publisher":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learning.workfall.com\/learning\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage","url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png","contentUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png","width":1200,"height":628,"caption":"Multer in Node.js"},{"@type":"WebPage","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage","url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/","name":"How to upload single or multiple images to a local directory with Multer in Node.js? - The Workfall Blog","isPartOf":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage"},"datePublished":"2022-08-30T11:27:22+00:00","dateModified":"2025-09-26T09:51:59+00:00","description":"If you want to know how to upload single or multiple images to a local directory with Multer in Node.js. Then this blog is for you!","breadcrumb":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learning.workfall.com\/learning\/blog\/"},{"@type":"ListItem","position":2,"name":"How to upload single or multiple images to a local directory with Multer in Node.js?"}]},{"@type":"Article","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#article","isPartOf":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage"},"author":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a"},"headline":"How to upload single or multiple images to a local directory with Multer in Node.js?","datePublished":"2022-08-30T11:27:22+00:00","dateModified":"2025-09-26T09:51:59+00:00","mainEntityOfPage":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#webpage"},"wordCount":1193,"publisher":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization"},"image":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/#primaryimage"},"thumbnailUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png","keywords":["api","Database","express","expressjs","images","javaScript","multer","node","nodeJS","workfall"],"articleSection":["Backend Development"],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a","name":"Workfall","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/image\/","url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png","contentUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png","caption":"Workfall"},"sameAs":["https:\/\/www.workfall.com"]}]}},"jetpack_featured_media_url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png","jetpack-related-posts":[{"id":226,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-build-and-deploy-a-mern-stack-application-on-aws\/","url_meta":{"origin":1187,"position":0},"title":"How to build and deploy a MERN Stack Application on AWS?","date":"October 27, 2021","format":false,"excerpt":"Do you have a wonderful product idea that keeps springing into your head? However, not sure which technology or framework to adopt for easier and faster deployment of scalable web applications, you can go for MERN Stack.\u00a0 A MERN Stack is a collection of front-end, back-end, and database components that\u2026","rel":"","context":"In &quot;AWS Cloud Computing&quot;","img":{"alt_text":"Build and Deploy a MERN Stack Application on AWS","src":"https:\/\/i2.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2021\/10\/MERN.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":921,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-export-data-to-a-csv-file-using-multiple-npm-packages-in-node-js\/","url_meta":{"origin":1187,"position":1},"title":"How to export data to a CSV file using multiple npm packages in Node.js?","date":"April 26, 2022","format":false,"excerpt":"Node.js is a single-threaded, open-source, cross-platform runtime environment treasured by developers for server-side and networking applications. And CSV format is one of the most widely used data interchange formats; it can be imported into any database and used in almost any other system. Moreover, it is backward compatible with everything.\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"How to export data to a CSV file using multiple npm packages in Node.js?","src":"https:\/\/i0.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/04\/Cover-Images_Part2-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1522,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-connect-to-mongodb-using-mongoose-and-mongodb-atlas-in-node-js\/","url_meta":{"origin":1187,"position":2},"title":"How to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js?","date":"November 29, 2022","format":false,"excerpt":"MongoDB is one of the most popular No-SQL databases in the developer community today. Instead of SQL objects, No-SQL databases allow developers to send and retrieve data as JSON documents. In this blog, we will demonstrate how to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js. Let\u2019s get\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"How to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js?","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/11\/Cover-Images_Part2-1-2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1121,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-show-flash-messages-in-node-js-using-the-connect-flash-package\/","url_meta":{"origin":1187,"position":3},"title":"How to Show Flash Messages in Node.js using the Connect-flash Package?","date":"August 9, 2022","format":false,"excerpt":"The Node.js Connect-flash module is extremely useful for developers whenever a flash message needs to be sent. When a user is redirected to a specific webpage, the connect-flash module in Node.js allows developers to display a pop-up message. For example, in your Node.js demo application, you might want to notify\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"Flash messages in Node.js","src":"https:\/\/i2.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":962,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-send-customized-emails-by-integrating-sendgrid-with-a-node-js-application\/","url_meta":{"origin":1187,"position":4},"title":"How to send customized emails by integrating SendGrid with a Node.js application?","date":"May 31, 2022","format":false,"excerpt":"Email is still one of the most popular forms of textual communication, particularly among corporations for notifications, outreach, etc. through their business product. SendGrid is one of the most widely used email APIs to integrate email services into business products. SendGrid makes it simple to send welcome emails, password reset\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"Send Customized emails by SendGrid","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/05\/Cover-Images_Part2-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1508,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-perform-encryption-and-decryption-of-messages-using-crypto-in-node-js\/","url_meta":{"origin":1187,"position":5},"title":"How to perform encryption and decryption of messages using Crypto in Node.js?","date":"November 8, 2022","format":false,"excerpt":"Web applications have access to massive amounts of data belonging to individuals, organizations, and governments. The more data that is accessed, the greater the risk to data security. Cryptography and encryption techniques are used by software developers to protect sensitive data from malicious parties. Cryptography is used to protect data\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"How to perform encryption and decryption of messages using Crypto in Node.js?","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/11\/Cover-Images_Part2-1.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1187"}],"collection":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/comments?post=1187"}],"version-history":[{"count":4,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1187\/revisions"}],"predecessor-version":[{"id":3021,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1187\/revisions\/3021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/media\/1188"}],"wp:attachment":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/media?parent=1187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/categories?post=1187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/tags?post=1187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}