title: How to Post data to Slack using NodeJs using axios?
body: <p>I am trying to understand an asynchronous function, to convert it into synchronous type for a use case,<br>
  The function is making a Post request to Slack using Node's https module,<br>I wish to convert this code to use the <code>axios</code> library.<br></p>
  
  <p>I am unable to understand what exactly is the Post Body being sent to the endpoint.<br></p>
  
  <p><strong>Function code as below -</strong></p>
  
  <pre><code>function postToSlack(logTitle, logMessage, logType, context) {
      var payloadStr = JSON.stringify({
          'username': slackBotUsername,
          'attachments': [
              {
                  'title': logTitle,
                  'fallback': logMessage,
                  'text': logMessage,
                  'color': getLogTypeColour(logType)
              }
          ],
          'icon_emoji': slackBotIconEmoji,
      });
  
      var options = {
          hostname: 'hooks.slack.com',
          port: 443,
          path: slackPostPath,
          method: 'POST',
          headers: {
              'Content-Type': 'application/json',
              'Content-Length': Buffer.byteLength(payloadStr),
          }
      };
  
      var postReq = https.request(options, function(res) {
          var chunks = [];
          res.setEncoding('utf8');
          res.on('data', function(chunk) {
              return chunks.push(chunk);
          });
          res.on('end', function() {
              var body = chunks.join('');
  
              if (res.statusCode &lt; 400) {
                  console.info('Message posted successfully');
              } else if (res.statusCode &lt; 500) {
                  console.error("Error posting message to Slack API: " + res.statusCode + " - " + res.statusMessage);
              } else {
                  console.error("Server error when processing message: " + res.statusCode + " - " + res.statusMessage);
              }
  
              if (completedRequests++ == totalRequests - 1) {
                  context.succeed('DONE');
              }
          });
          return res;
      });
  
      postReq.write(payloadStr);
      postReq.end();
  }
  </code></pre>
  
  <p>I want to know if,<br>
  <strong>options</strong> is the raw request post body?,<br>
  or is <code>options</code> just used to construct the <strong>endpoint</strong> and <strong>headers</strong>?<br></p>
  
  <p>Is my understanding correct that there is no Post request body,<br>
  But just an https <code>endpoint</code> and <code>headers</code>?</p>
  
  <p><strong>Reference -</strong><br>
  <a href="https://flaviocopes.com/node-http-post/" rel="nofollow noreferrer">https://flaviocopes.com/node-http-post/</a></p>