0

multer.js

I am using multer@2.0.0-rc.1, according to their documentation the code is as follows

const multer = require("multer");
const upload = multer().single("avatar");

module.exports = { upload };

Userroute.js

 const { upload } = require("../middleware/multer");
 router.route("/register").post(upload, registerUser);

Controller for User Registration

I am not able to access the req object. The error is shown after code

const catchAsyncError = require("../../middleware/catchAsyncError");
const ErrorHandler = require("../../utils/errorhandler");
const cloudinary = require("cloudinary").v2;
 exports.registerUser = catchAsyncError(async (req, res, next) => 
 {
   console.log(req.body);
   console.log(req.file);
 });

Console

[Object: null prototype] {}
null
Abhishek Vyas
  • 599
  • 1
  • 9
  • 24

1 Answers1

-2

Try modifying the module. Exports to module.exports and also

const upload = multer().single("avatar");

can be changed to

const upload = multer.single("avatar");

Hope this works.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Pratik
  • 1
  • 1