title: send an image to the database and store the image in static
body: <p>I am using nodejs express js, send an image to the database and store the image statically, usually the way I do it works fine, but this time it doesn't work and I can't find where the error is .I've been stuck on it since yesterday morning.when I try to post an image it does not retrieve its name I receive undefined. On the frontend side everything is sent well, until the backend I traced. It is at the backend level that it is blocked. Thank you in advance for your help</p>
  <p>file multer config:</p>
  <pre><code>const multer = require('multer');
  
  const MIME_TYPES = {
      'image/jpg': 'jpg',
      'image/jpeg': 'jpg',
      'image/png': 'png',
  };
  
  const storage = multer.diskStorage({
      destination: (req, file, callback) =&gt; {
          callback(null , 'images')
      },
      filename: (req, file, callback)=&gt; {
          const name = file.originalname.split(' ').join('_'); 
          const nameFile = name.split(&quot;.&quot;)[0]
          const extension = MIME_TYPES[file.mimetype]; 
          callback(null, nameFile + Date.now() + '.' + extension);
      }
  })
  
  module.exports = multer({ storage: storage }).single('images');
  </code></pre>
  <p>file app</p>
  <pre><code>let path = require('path');
  app.use('/images', express.static(path.join(__dirname +'/images')))
  </code></pre>
  <p>file request</p>
  <pre><code>exports.createPatisserie = `INSERT INTO patisseries 
  SET id_admin=?, nomProduit= ?, ingredients= ?, prix= ?, idBoutique= ?, imageUrl= ?`
  </code></pre>
  <p>file controller</p>
  <pre><code>exports.createPatisserie = (req, res)=&gt;{
      const {nomProduit, ingredients, prix, idBoutique} = req.body
      const imageUrl = `${req.protocol}://${req.get('host')}/images/${req.file?.filename}`
      connection.query(patisserie.createPatisserie,[1,nomProduit, ingredients, prix,idBoutique, imageUrl], (error, result)=&gt;{
          console.log(imageUrl)
          if(error){
              res.status(400).json({error: error, message: httpRequestMessagesPatisserie.errorCreatePatisserie})
          }else{
              res.status(200).json({result, message: httpRequestMessagesPatisserie.successCreatePatisserie})
          }
      })
  }
  
  </code></pre>