On the server, to process the request to the update API that may now contain a file, we will use the formidable npm module:
npm install --save formidable
Formidable will allow us to read the multipart form data, giving access to the fields and the file, if any. If there is a file, formidable will store it temporarily in the filesystem. We will read it from the filesystem, using the fs module to retrieve the file type and data, and store it to the photo field in the user model. The formidable code will go in the update controller in user.controller.js as follows.
mern-social/server/controllers/user.controller.js:
import formidable from 'formidable'import fs from 'fs'const update = (req, res, next) ...