'Net to setup simple if and else statement in node.js

trying to setup node.js code i want to setup simple if and else can anyone help to setup if and else

   // To use any npm package on Pipedream, just import it
import axios from "axios"

export default defineComponent({
  async run({ steps, $ }) {
    const { data } = await axios(
            {
      method: "POST",
  url: `http://xxx.xx.xx.xxx:3000/message/text?key=kjashdkasdhkjashsad`,
  if(steps.trigger.event.body.info.to_pincode == '411045' )
  {
  data: {
        id: "919999999999",
        message: 'Name steps.zoho_books.$return_value.contacts[0].contact_name\nItem Name steps.trigger.event.body.product_name\nAWB steps.trigger.event.body.courier_tracking_id\nCourier Name steps.trigger.event.body.courier_parent_name\nCurrent Location steps.trigger.event.body.status.current_status_location \nCurrent Status steps.trigger.event.body.status.current_status_body\nDelivery City steps.trigger.event.body.info.to_city\nDelivery State steps.trigger.event.body.info.to_state\nEstimated Delivery Date steps.trigger.event.body.edd_stamp  }}
        else{
  data: {
        id: "919999999999",
        message: 'Else steps.zoho_books.$return_value.contacts[0].contact_name\nItem Name steps.trigger.event.body.product_name\nAWB steps.trigger.event.body.courier_tracking_id\nCourier Name steps.trigger.event.body.courier_parent_name\nCurrent Location steps.trigger.event.body.status.current_status_location \nCurrent Status steps.trigger.event.body.status.current_status_body\nDelivery City steps.trigger.event.body.info.to_city\nDelivery State steps.trigger.event.body.info.to_state\nEstimated Delivery Date steps.trigger.event.body.edd_stamp  }}
    })
    return data.species
  },
})


Solution 1:[1]

Try to use a conditional operator to define your data object:

import axios from 'axios';

export default defineComponent({
  async run({ steps, $ }) {
    const dataObj =
      steps.trigger.event.body.info.to_pincode == '411045'
        ? {
            id: '919999999999',
            message: 'if',
          }
        : { id: '919999999999', message: 'else' };

    const { data } = await axios({
      method: 'POST',
      url: `http://xxx.xx.xx.xxx:3000/message/text?key=kjashdkasdhkjashsad`,
      data: dataObj,
    });

    return data.species;
  },
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lpizzinidev