I am building an API using ExpressJS.In one of the endpoints I need to create an account with an optional avatar.
So, I want to upload the avatar if avatar was provided before creating an account, but if no avatar was provided I just want to go ahead and still create the account.
I have the following code to check if avatar exists but it always returns undefined even though available.
createAccount: async (req, res) => {
let avatar = req.file.avatar;
if (avatar) {
console.log("Avatar Found"); //Even when I include avatar, I still get undefined here;
} else {
console.log("No Avatar Found");
}
},