title: How to fix 502 error getting on post request?
body: <p>I have node.js app that upon click of a button send post request and on post request email should be sent to the admin. The page link from where I initiate request can be found here: <a href="https://blockmmerce.io/views/contact" rel="nofollow noreferrer">https://blockmmerce.io/views/contact</a>. </p>
  
  <p>As soon as I click the button the event listener is called but it tries to send the request and returns back with 502 error code. </p>
  
  <p>any possible fix?</p>
  
  <p>contact.js: </p>
  
  <pre><code>$(document).ready(function () {
  console.log("here...")
  var enquirybutton = document.querySelector('#sendEnquiry');
  enquirybutton.addEventListener('click', function (event) {
      alert("clicked!!");
      let name = $('#name').val();
      let email = $('#email').val();
      let message = $('#message').val();
      event.preventDefault();
      $.ajax({
            url: "/sendEnquiry",
            dataType: "json",
            type: "post",
            cache: false,
            data: ({
              "name": name,
              "email": email,
              "message": message
            }),
            success: function (response) {
              alert("Enquiry sent successfully !!!")
            },
            error: function (textStatus, errorThrown) {
              console.log("Error::::" + errorThrown);
              console.log("status::::" + String(textStatus));
            }
          }); 
  });
  
  });
  </code></pre>
  
  <p>Index.js:</p>
  
  <pre><code>    var express = require('express');
  var router = express.Router();
  var emailConfig = require('../config/email.config.js');
  
  router.post('/sendEnquiry', function (req, res, next){
      let name = req.body.name;
      let email = req.body.email;
      let message = req.body.message;
      emailConfig.sendEmail(
          'admin@blockmmerce.io',
          'Enquiry',
          `this is first query`
      );
      res.json({});
      console.log("hello from send enquiry");
  });
  
  modules.exports = export;
  </code></pre>
  
  <p>email.config.js:</p>
  
  <pre><code>var nodemailer = require('nodemailer');
  
  //--------------------------------------------------------
  // Declarations    
  //--------------------------------------------------------
  var senderEmail = 'info@server119.web-hosting.com';
  // var password = '----';
  //--------------------------------
  // Mail Sending Email
  //--------------------------------------------------------
  var transporter = nodemailer.createTransport({
      host: 'server119-3.web-hosting.com',
      secure: true,
      port: 465,
      auth: {
          user: 'info@blockmmerce.io',
          pass: '------'
      }
  });
  
  // ================================================================
  // handle Sendmail
  // ================================================================
  
  var sendEMail = (emailId, subject, mailcontent) =&gt; {
      let mailOptions = {
          from: senderEmail,
          to: emailId,
          subject: subject,
          html: mailcontent
      };
      return new Promise(function (resolve, reject) {
          transporter.sendMail(mailOptions, function (err, info) {
              if (err) {
                  reject(err);
              } else {
                  resolve(info);
              }
          });
  
      });
  }
  
  //--------------------------------------------------------
  // Exporting All functions
  //--------------------------------------------------------
  
  module.exports = {
      transporter,
      senderEmail,
      sendEMail
  }
  </code></pre>