title: Express server sending multipart form data with text fields to an external api
body: <p>I am creating a rest API server in Express.js. The goal of this of my particular issue is creating a post route that takes multipart/form-data request and sends file/text/field to an external API. At the moment I am running into an issue even trying to test it with postman.</p>
  <p>I can send a response with the parsed data from multer, but when I try to create a new form-data I cannot access the request body, TypeError: Cannot read property 'name' of null</p>
  <p>What am I doing wrong? Is there a better way? Open to suggestions.</p>
  <p>My server code is as follows:</p>
  <pre><code>const express = require(&quot;express&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  const cors = require(&quot;cors&quot;);
  const request = require(&quot;request&quot;);
  const multer = require(&quot;multer&quot;);
  const upload = multer({ dest: 'uploads/'});
  const FormData = require(&quot;form-data&quot;);
  const fs = require(&quot;fs&quot;);
  
  const app = express();
  const port = 3000;
  
  app.use(cors());
  
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(bodyParser.json());
  
  ///.....
  
  app.post('/jobs/:id', upload.single('resume'), (req, res) =&gt; {
  
      let url = '...';
  
      var header = req.headers['content-type']
  
      var tmp_path = req.file.path;
      var tar_path = 'uploads/' + req.file.originalname;
      var src = fs.createReadStream(tmp_path);
      var dest = fs.createWriteStream(tar_path);
      src.pipe(dest);
  
      var data = new FormData();
      data.append('name', req.body.name)
      data.append('phone', req.body.phone)
      data.append('email', req.body.email)
      data.append('resume', fs.createReadStream(tar_path))
      
      const options = {
          url: url,
          method: 'POST',
          headers:{
              'Content-Type': header
          },
          formData: data
      }
  
      request(options, (err, rez, body) =&gt; {
          if (err){
              console.log(&quot;There was an error: &quot; + err)
          }
      }).pipe(res)  
  
      res.send(res)
  })
  
  
  app.listen(port, () =&gt; console.log(`Server is listening on port ${port}`));
  </code></pre>
  <h3>EDIT</h3>
  <p>This is the request I am trying to make:</p>
  <pre><code>curl -F name=&quot;test&quot; -F phone=&quot;0000000000&quot; -F email=&quot;test@test.com&quot; -F resume=@&quot;Desktop/test.txt&quot; http://cfr.thewb.co/jobs/408189/
  </code></pre>