we have to also check is req.files.avatar? if yes than we can access its [0] otherwise its show this error if user not send avatar file : TypeError: Cannot read properties of undefined (reading '0') --> so right way is const avatarLocalPath = req.files?.avatar?.[0]?.path; to access avatar local path
we have to also check is req.files.avatar? if yes than we can access its [0] otherwise its show this error if user not send avatar file : TypeError: Cannot read properties of undefined (reading '0') --> so right way is const avatarLocalPath = req.files?.avatar?.[0]?.path; to access avatar local path