Let's start by creating the endpoint to upload avatar photos:
var controller = require('./controller');
Express itself does not process files automatically; it needs a plug-in that transforms the raw request into a more user-friendly API. This plug-in is named
multer; it processes
multipart/form-data, saving the file into a temporary path or making a buffer object, and then provides a JSON object with metadata information:
// Avatar endpoints var upload = multer(); server.post('/api/contacts/:contactId/avatar', upload.single('avatar'), controller.uploadAvatar ); server.use('/avatar', express.static(__dirname + '/avatar')); ...