title: How to send an alert from node.js express function
body: <p>Hi and thanks in advance,</p>
  
  <p>I am using the following function in my main.js to send a contact us email. Upon success I am simply redirecting back to home.  </p>
  
  <p>How do I send the client a simple alert("Email Sent: Success"); to the client browser.</p>
  
  <p>from main.js </p>
  
  <pre><code>app.use(bodyParser.json());
  
  app.get('/sendMail', function(req, res){
  
   res.sendFile("index.html"); // html file is within public directory
  });
  
  
      app.post('/sendMail',function(req,res){
     var username = req.body.name;
     var subject = req.body.subject;
     var fromEmail = req.body.email;
     var toEmail = 'support@domain.my';
     var bodyMessage = req.body.message;
  
    //  var htmlData = 'Hello:  ' + toEmail;
  
  var mg = new Mailgun('key-0000000000000000000');
  mg.sendText(fromEmail, toEmail,
    'CS: '+subject,
    bodyMessage,
    fromEmail, {},
    function(err) {
      if (err)res.send('NOT SENT: STRUGGLE EVERYDAY');
      else res.redirect('/');
      // res.json({success: true});
      // else     res.send('Success: EMAIL SENT From: '+fromEmail+'  -  To: '+toEmail);
  }); 
  
  });
  </code></pre>
  
  <p>from my index.html page button to send..</p>
  
  <pre><code>&lt;!-- START CONTACT FORM --&gt;
  
              &lt;form method="POST" action="sendMail" accept-charset="UTF-8" class="contact-form" id="jvalidate" novalidate="novalidate"&gt; 
  
                  &lt;div class="row"&gt;
                      &lt;div class="col-sm-12 col-md-4"&gt;
                          &lt;div class="field-holder"&gt;
                              &lt;input class="form-control input-lg field" placeholder="John Snow" name="name" type="text"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-12 col-md-4"&gt;
                          &lt;div class="field-holder"&gt;
                              &lt;input class="form-control input-lg field" placeholder="yourEmail@Address.com" name="email" type="email"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-12 col-md-4"&gt;
                          &lt;div class="field-holder"&gt;
                              &lt;input class="form-control input-lg field" placeholder="Subject" name="subject" type="text"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-md-12 col-xs-12"&gt;
                          &lt;div class="field-holder"&gt;
                              &lt;textarea class="form-control" placeholder="Some text" name="message" cols="50" rows="10"&gt;&lt;/textarea&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group"&gt;
                          &lt;div class="col-md-12"&gt;  
                              &lt;div class="alert alert-success" role="alert" style="display: none;"&gt;
                                  Message has been successfully sent.
                              &lt;/div&gt;
                              &lt;div class="alert alert-danger" role="alert" style="display: none;"&gt;
                                  &lt;div class="alert-text"&gt;Server error&lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-md-12"&gt;
                          &lt;button class="btn btn-primary btn-contact" type="submit" value="SEND MESSAGE"&gt;SEND MESSAGE&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
              &lt;!-- END CONTACT FORM --&gt;
  </code></pre>
  
  <p>If code does not allow it, are there any modules I can install for this ?</p>
  
  <p>New to node and js. Thanks for the help.</p>