title: TypeError: Cannot read property 'then' of undefined in node js
body: <p>this is the .sms file . I'm trying to call an resendOTP api but im geeting an error that <code>.then is undefined</code></p>
  <pre><code>   var aws = require('aws-sdk')
  
     aws.config.update({
       region: '********',
       accessKeyId: &quot;********&quot;,
       secretAccessKey:&quot;*********&quot;
    });
  
     var sns = new aws.SNS();
      sns.setSMSAttributes({
       attributes: { DefaultSMSType: &quot;Transactional&quot; }
     },
     function (error) {
       if (error) {
        console.log(error);
     }
    });
  
     function sendSms(phoneNumber, body) {
    // console.log(`Sending SMS. Phone: ${phoneNumber}, body: ${body}`);
      var params = {
        Message: body,
        MessageStructure: 'string',
        PhoneNumber: phoneNumber
      };
  
  sns.publish(params, function (err, data) {
      if (err) {
          console.log(err, err.stack); // an error occurred
      }
      else {
         // console.log(data);           // successful response
      }
   });
  }
  
  module.exports = sendSms
  </code></pre>
  <p><code>.then</code> is showing undefined.</p>
  <pre><code> exports.resendOTP = async( req, res) =&gt; {
     const { id } = req.body;
     const user = await  User.findOne({ _id : id })
     if (!user) {
        res.status(200).send({
           message: &quot;User was not found&quot;
        });
     }
    else {
      var OTP = Math.floor(1000 + Math.random() * 9000);
      var encryptOTP = encrypt(OTP.toString());
      var body = 'Hi, '+OTP+' is your One Time Password.';
    sendSms(user.countryCode+user.phoneNumber, body).then(message =&gt; {
      if (message) {
      res.status(200).send({
        message: &quot;Updated Sucessfully&quot;
      });
      }
    }) 
  } 
  </code></pre>
  <p>}</p>