title: What is the definitive way to use Gmail with OAuth and Nodemailer?
body: <p><strong>Desired Behaviour</strong></p>
  
  <p>Use <code>Gmail</code>, <code>OAuth2</code> and <code>Nodemailer</code> to send an email from a server side <code>node.js</code> file.  </p>
  
  <p><strong>What I've Tried</strong></p>
  
  <p><em>Relevant Documentation</em></p>
  
  <p><a href="https://nodemailer.com/smtp/oauth2" rel="noreferrer">https://nodemailer.com/smtp/oauth2</a><br>
  <a href="https://nodemailer.com/usage/using-gmail" rel="noreferrer">https://nodemailer.com/usage/using-gmail</a><br>
  <a href="https://developers.google.com/gmail/api/auth/web-server" rel="noreferrer">https://developers.google.com/gmail/api/auth/web-server</a>  </p>
  
  <p><em>Relevant Questions</em>   </p>
  
  <p><a href="https://stackoverflow.com/questions/42802598/send-emails-from-my-gmail-account-with-oauth2-and-nodemailer">send emails from MY gmail account with OAuth2 and nodemailer</a><br>
  <a href="https://stackoverflow.com/questions/19766912/how-do-i-authorise-an-app-web-or-installed-without-user-intervention">How do I authorise an app (web or installed) without user intervention?</a><br>
  <a href="https://stackoverflow.com/a/47936349">https://stackoverflow.com/a/47936349</a><br>
  <a href="https://stackoverflow.com/a/22572776">https://stackoverflow.com/a/22572776</a>  </p>
  
  <p>There were gaps in the instructions of the above sources and some information was outdated, so the answer below was my final implementation which appears to be working. </p>
  
  <p>I'm posting this solution for confirmation it is best practice and, if it is, to save others time.    </p>