title: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client, i can't send a form to realtime database
body: <ol>
  <li>this my html code submit</li>
  </ol>
  <pre><code>&lt;form action=&quot;/user/product/add&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot; &gt;
                          &lt;h1 class=&quot;h&quot;&gt;Add Product&lt;/h1&gt;
                          &lt;div&gt;
                              &lt;table class=&quot;tableez&quot; cellpadding=&quot;4&quot; cellspacing=&quot;0&quot; style=&quot;width:400px&quot;&gt;
                                  &lt;tr&gt;
                  
                                      &lt;div class=&quot;form-group&quot;&gt;
                                          &lt;input type=&quot;file&quot; name=&quot;imageProduct&quot; multiple&gt;
                                      &lt;/div&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td class=&quot;tdtitle&quot;&gt;Tên sản phẩm: &lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; value=&quot;{{data.nameProduct}}&quot; name=&quot;nameProduct&quot;
                                              id=&quot;nameProduct&quot;&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                          &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Thêm&lt;/button&gt;
                      &lt;/form&gt;
  </code></pre>
  <ol start="2">
  <li>this is my api</li>
  </ol>
  <pre><code>router.post('/product/add', upload.array('imageProduct', 5), isLoggedIn, function (req, res, next) {
   
      var idd = &quot;5ea4528ccaf1ab0017e0fe22&quot;;
      var filesImage = req.files;
      var images = [];
      filesImage.forEach(function (item, index, array) {
        images.unshift(item.filename);
      });
      var winner = [];
      winner.unshift(&quot;1&quot;);
      winner.unshift(&quot;Chưa có&quot;);
      //  var messages = [];
      // messages.unshift({
      //     a : &quot;qwe&quot;,
      //     b : &quot;asdq&quot;
      // });
  
      var played = [];
      played.unshift(&quot;null&quot;);
      var registerDatee = Date.now();
      var time = req.body.time;
      console.log(time);
      const product = {
        imageProduct: images,
        nameProduct: req.body.nameProduct,
        userId: idd,
        nameProductType: req.body.cars,
        startPriceProduct: req.body.currentPrice,
        status: req.body.status,
        description: req.body.description,
        extraTime: req.body.time,
        registerDate: registerDatee,
        winner: winner,
        hide: false,
        currentPrice: req.body.currentPrice,
        played: played
      };
  
      var db = Firebase.database();
      var rootRef = db.ref('products');
      rootRef.push(product);
      res.redirect('/');
  
  });
  </code></pre>
  <p>After I clicked submit, the following error occurred
  3. this is my error</p>
  <pre><code>POST /user/product/add 200 151.592 ms - -
  _http_outgoing.js:526
      throw new ERR_HTTP_HEADERS_SENT('set');
      ^
  
  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at ServerResponse.setHeader (_http_outgoing.js:526:11)
      at ServerResponse.header (C:\Users\HaAnh\Desktop\api\backend-app-daugia\node_modules\express\lib\response.js:767:10)
      at ServerResponse.contentType (C:\Users\HaAnh\Desktop\api\backend-app-daugia\node_modules\express\lib\response.js:595:15)
      at ServerResponse.send (C:\Users\HaAnh\Desktop\api\backend-app-daugia\node_modules\express\lib\response.js:145:14)
      at done (C:\Users\HaAnh\Desktop\api\backend-app-daugia\node_modules\express\lib\response.js:1004:10)
      at Immediate._onImmediate (C:\Users\HaAnh\Desktop\api\backend-app-daugia\node_modules\express-handlebars\lib\utils.js:26:4)
      at processImmediate (internal/timers.js:456:21) {
    code: 'ERR_HTTP_HEADERS_SENT'
  }
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  <p>I do not understand why I submitted an error after I submitted it, but it is okay to fix, I have read a lot of the above questions, but there is still no solution for my project. I'm crying because I don't know what to do next.
  <strong>Although an error has occurred, the product has been saved in the database.</strong>
  Please give me a solution so I can continue working on my project!</p>