node.js – express-fileupload requires me to upload a file which is optional on the form

I have a challenge with express-fileupload when a user doesn’t upload a file that is meant to be optional.
Someone should please help me out.

Find the image of my code here:
express-fileupload problem

const file = req.files.document;
  const file2 = req.files.document2;
  const uploader = req.body.fullname;

  const filename = `CV_${uploader}_${}`;
  const filename2 = `Cover_${uploader}_${}`;
  let savedFile = filename.replace(/\s+/g, "");
  let savedFile2 = filename2.replace(/\s+/g, "");
  const path = "uploads/" + savedFile;
  const path2 = "uploads/" + savedFile2;, (err) => {
    if (err) {
  });, (err) => {
    if (err) {

The second file is optional for the user to upload. When the user doesn’t upload it, it shows an error.
Please, how can I make it optional from here.

It shows an error like this:
Type Error: Cannot read property ‘name’ of undefined

Thank you so much.

Read more here: Source link