title: transporter.sendMail is not a function, I have used node.js with nodemailer
body: <p>This is my <code>app.js</code> file this code seems to be correct, but gets an <code>transporter.sendMail is not a function</code> error.</p>
  <pre class="lang-js prettyprint-override"><code>const links = document.querySelectorAll('.link');
          
  links.forEach(link =&gt; {
      link.addEventListener('click', () =&gt;{
          links.forEach(ele =&gt; ele.classList.remove('active'));
          link.classList.add('active');
      })
  })
  
  // contact form
  const contactBtn = document.querySelector('.contact-btn');
  const firstName = document.querySelector('.first-name');
  const lastName = document.querySelector('.last-name');
  const email = document.querySelector('.email');
  const msg = document.querySelector('.message');
  
  contactBtn.addEventListener('click', () =&gt; {
      if(firstName.value.length &amp;&amp; 
          lastName.value.length &amp;&amp; email.value.length &amp;&amp; msg.value.length ){
              fetch('/mail', {
                  method: 'post',
                  headers: new Headers({'Content-Type': 'application/json'}),
                  body: JSON.stringify({
                      firstname: firstName.value,
                      lastname: lastName.value,
                      email: email.value,
                      msg: msg.value,
                      
                  })
                  .then(res =&gt; res.json())
                  .then(data =&gt; {
                      alert(data);
                  })
              })
          }
  })
  </code></pre>
  <p>This is my <code>server.js</code> file. What is the error in this file? I have trying this since few hours, but not getting the output. I'm a beginner and trying this project of sending mail using <code>nodemailer</code>.</p>
  <pre class="lang-js prettyprint-override"><code>const express = require('express');
  const path = require('path');
  const nodemailer = require('nodemailer');
  const dotenv = require('dotenv');
  
  var firstname = '#';
  firstname.substring(1); 
  var lastname = '#';
  lastname.substring(1); 
  var email = '#';
  email.substring(1); 
  var msg = '#';
  msg.substring(1); 
  var transporter = '#';
  transporter.substring(1);
  
  dotenv.config();
  let initialPath = path.join(__dirname, &quot;public&quot;);
  let app = express();
  
  app.use(express.static(initialPath));
  app.use(express.json());
  
  app.get('/', (req, res) =&gt; {
      res.sendFile(path.join(initialPath, &quot;index.html&quot;));
  })
  
  app.post('/mail', (req, res) =&gt; {
      const { firstname, lastname, email, msg } = req.body;
  
      
      let transporter = nodemailer.createTransport({
          service: 'gmail',
          auth: {
              user: process.env.EMAIL,
              pass: process.env.PASSWORD
          }
      })
  })
  
  const mailOptions = {
      from: 'yyy@gmail.com',
      to: 'xxx@gmail.com',
      subject: 'Portfolio',
      text: `First name: ${firstname}, \nLast name: ${lastname}, 
      \nEmail: ${email}, \nMessage: ${msg}`
  }
  
  transporter.sendMail(mailOptions, (err, result) =&gt; {
      if (err){
      console.log(err)
          res.json('Oops error occurred')
      } else{
          res.json('thanks for emailing me');
      }
  })
  
  app.listen('3000', () =&gt; {
      console.log('listening....');
  })
  </code></pre>