title: send CSV file stored in my computer using NodeJS to another Server using Post method
body: <p>I am required to send a CSV file stored in my computer to another external API.
  The CSV file contains some data and it is stored in my computer
  I need to create an API in NodeJS that sends this CSV file to another server using POST method and with the right headers like:</p>
  <p>-H 'accept: application/json'
  -H 'Authorization: Bearer token
  -H 'Content-Type: multipart/form-data'
  -F 'csvFile=@New1.csv;type=text/csv'</p>
  <p>How can it be achieved?
  Please help
  Thanks</p>
  <pre><code>const dbConnect = require('../../config/dbConnect')
  const mssql = require('mssql/msnodesqlv8')
  const DBConstants = require('../utils/constants')
  const dbConfig = require('../../config/database')
  const converter = require('json-2-csv')
  const fs = require('fs')
  const axios = require('axios')
  const https = require('https')
  const formData = require('form-data')
  
  module.exports.getData = async(req, res) =&gt; {
      const httpsAgent = new https.Agent({rejectUnauthorized: false}) 
      const form_data = new formData()
      let pool, result, request_config
      var token
      // get data from sp
      try {
          pool = await dbConnect
          result = await pool.request()
              .input(**************)
              .input(************)
              .execute(**********)
      } catch (err) {
          console.log('Error fetching records from store procedure', err)
      }
  
      // convert fetched data into csv
      converter.json2csv(result.recordsets[0], (err, csv) =&gt; {
          if(err) {
              throw err
          } else {
              fs.writeFileSync('DATA.csv', csv)
          }
      })
      form_data.append('csvFile', fs.createReadStream(&quot;DATA.csv&quot;))
      // login to external API
      axios.post('/api/v1/user/login', {
          email: 'login_email',
          password: 'login_pass'
          }, { httpsAgent } )
          .then(response =&gt; {
              token = response.data.token
              // now create request_config
              request_config = {
                  headers: {
                      &quot;accept&quot;: &quot;application/json, text/csv&quot;,
                       &quot;Authorization&quot;: &quot;Bearer &quot; + token,
                       &quot;Content-Type&quot;: &quot;multipart/form-data&quot;,
                       ...form_data.getHeaders()
                  },
                  httpsAgent,
                  maxContentLength: Infinity,
                  maxBodyLength: Infinity,
              }
          })
          .catch(err =&gt; {
              console.log(err)
          }) 
  // Making the Upload Call       
  axios.post('/api/v1/amc/upload/', form_data, request_config)
              .then(response =&gt; {
                  res.json(response)
              })
              .catch(err =&gt; {
                  console.log('error in upload', err)
              })
          res.json(result.recordsets[0]) 
      }
  </code></pre>