1const multer = require('multer')
2
3const storage = multer.diskStorage({
4 destination: function (req, file, cb) {
5 cb(null, 'uploads/')
6 },
7 filename: function (req, file, cb) {
8 cb(null, file.filename + '-' + Date.now())
9 }
10})
11
12const upload = multer({ storage: storage })
13
14// For Single uploads
15router.route('/upload').post(upload.single('file'), (req, res, next) => { return res.json(req.file) })
16
17// For multiple file uploads (using FormData)
18router.route('/upload').post(upload.array('file[]'), (req, res, next) => { return res.json(req.file) })