Cannot app.use(multer). “requires middleware function” error

You need to use app.use(multer({dest:'./uploads/'})) in the form of one of these:

app.use(multer({dest:'./uploads/'}).single(...));
app.use(multer({dest:'./uploads/'}).array(...));
app.use(multer({dest:'./uploads/'}).fields(...));

ie:

app.use(multer({dest:'./uploads/'}).single('photo'));

And be sure to have something like:

<form action="/postPhotos" enctype="multipart/form-data" method="post">
    <input type="file" name="photo">
    <input type="submit" value="Upload photo">
</form>

In your html.

Leave a Comment