On your base app directory, create a folder as such:
mkdir -p public/uploads
Install multer in order to handle multipart/form-data
npm i multer
Import multer before you can use it
const multer = require('multer');
Initiate disk storage
var storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './public/uploads')
},
filename: (req, file, cb) => {
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname))
}
});
//will be using this for uplading
const upload = multer({ storage: storage });
Add this to serve static assets
app.use('/ftp', express.static('public'), serveIndex('public', {'icons': true}));
Put this below your other middleware functions.
app.use(express.static('public'));
Great Job!