Home > Back-end >  files.forEach((file) => { TypeError: Cannot read properties of undefined (reading 'forEach&#
files.forEach((file) => { TypeError: Cannot read properties of undefined (reading 'forEach&#

Time:01-29

I already search solutions for this problem but all I can find is "missing semi colon" which is obviously not my problem... Here are the code and its error

Node.JS MongoDB File-Upload

Can anyone help me?

I already search solutions for this problem but all I can find is "missing semi colon" which is obviously not my problem

CodePudding user response:

Use fs.readdirSync in line 41 instead.

CodePudding user response:

Based on the error log you provided, the files Is not defined. Add a guard clause at line 47 to check field exist before running the code

if (files && files.length >0){

//original line 47-52
}
  • Related