title: ERR_STREAM_WRITE_AFTER_END while using request promise Node Js
body: <p>I have request promise that use to call another API with few loads here's my request promise</p>
  
  <p>here's my container</p>
  
  <pre><code>    if (!req.uploadedFile2) {
          opt2 = {
              method: 'POST',
              body: {
                  token: req.body.token,
                  name: req.body.name,
                  id_type: req.body.id_type,
                  id_no: req.body.id_no,
                  mobile_phone: req.body.phone,
                  email: req.body.email,
                  address: req.body.address,
                  postal_code: req.body.postal_code,
                  dob: req.body.dob,
                  product_code: req.body.product_code,
                  billing_phone: req.body.billing_phone,
                  callback_url: 'purchase',
  
              },
              formData: {
                  images: fs.createReadStream(req.uploadPic),
              },
              uri: `${process.env.Heeey}purchase/test/test_more`,
              json: true,
          };
      }
  
      const obj = {
          name: req.body.name,
          id_no: req.body.id_no,
          id_type: req.body.id_type,
          mobile_phone: req.body.phone,
          birth_date: moment(req.body.dob, 'DD-MM-YYYY').format('YYYY/MM/DD'),
          postal_code: req.body.postal_code,
      };
  
  
  
  </code></pre>
  
  <p>and here's where i will send my request promise after creating dbUserContainer</p>
  
  <pre><code>    return dbUserContainer
          .create(obj)
          .then(() =&gt; rp(opt2)
              .then((results) =&gt; {
                  setContent(200, results.result);
                  return res.status(200).json(getContentSuccess());
              }).catch((error) =&gt; {
                  setContent(400, error);
                  return res.status(400).json(getContentFailOutside(error));
              }))
          .catch((error) =&gt; {
              setContent(400, error);
              return res.status(400).json(getContentFailOutside(error));
          });
  
  </code></pre>
  
  <p>when I execute this code via postman I always get this message </p>
  
  <pre><code>{
      "code": "ERR_STREAM_WRITE_AFTER_END"
  }
  </code></pre>
  
  <p>after research, I tried to use time out to gives time for the fs.createReadStream to read and transport it here's what i have tried so far</p>
  
  <pre><code>    return dbUserContainer
          .create(obj)
          .then(() =&gt; {
              const dataRP = () =&gt; rp(opt2)
                  .then((results) =&gt; {
                      setContent(200, results.result);
                      return res.status(200).json(getContentSuccess());
                  }).catch((error) =&gt; {
                      setContent(400, error);
                      return res.status(400).json(getContentFailOutside(error));
                  });
  
              setTimeout(dataRP, 2000);
          })
          .catch((error) =&gt; {
              setContent(400, error);
              return res.status(400).json(getContentFailOutside(error));
          });
  </code></pre>
  
  <p>but I always get but unfortunately, i get the same error message in the postman stating ERR_STREAM_WRITE_AFTER_END t the same error </p>