What will be the nodejs equivalent of PHP curl code [duplicate] What will be the nodejs equivalent of PHP curl code [duplicate] curl curl

What will be the nodejs equivalent of PHP curl code [duplicate]


The axios equivalent of CURLOPT_POSTFIELDS, http_build_query($postfields) is twofold - first stringify the params and pass them as the post body and secondly specify application/x-www-form-urlencoded as the content type in the headers.

Something like this:

const axios = require('axios')const qs = require('qs')const data = qs.stringify(postFieldsObject)const config = {  method: 'post',  url: `${whmcsUrl}includes/api.php`,  headers: {     'Content-Type': 'application/x-www-form-urlencoded'  },  data : data}axios(config).then(function (response) {  console.log(JSON.stringify(response.data))}).catch(function (error) {  console.log(error)})