In this tutorial, we are going to learn how to upload images on the server with multer and express in Node.js. File upload is a common operation for any project. Node.js with the Express Web Framework and the multer Library, this tutorial we adding a file upload feature to your app is very easy. You will learn in this tutorial to make you comfortable in building apps that can easily handle any file uploads.

  • We will be covering the following topics:
  • What is Multer?
  • Project Setup
  • Adding Multer
  • Disk Storage

File Upload With Multer In Node.js And Express

This is image title

Adding Multer

npm install multer --save

const multer = require('multer');
const upload = multer({dest:'uploads/'}).single("demo_image");

The following code will go in app.js:

app.post("/image", (req, res) => {
   upload(req, res, (err) => {
    if(err) {
      res.status(400).send("Something went wrong!");
    }
    res.send(req.file);
  });
});

Original Source :File Upload With Multer In Node.js And Express

#node #express #javascript

File Upload with Multer in Node.js and Express - Php Coding Stuff
20.80 GEEK