title: How to use pdf output of PDFMake in the attachment mail options of NodeMailer?
body: <p>Here is a one of PDFMake's code snippet to <a href="https://github.com/bpampuch/pdfmake/blob/master/examples/absolute.js#L153" rel="nofollow">create pdf file</a>:</p>
  
  <pre><code>var pdfDoc = printer.createPdfKitDocument(docDefinition);
  pdfDoc.pipe(fs.createWriteStream('pdfs/absolute.pdf'));
  pdfDoc.end();
  </code></pre>
  
  <p>and here is one of the <a href="https://github.com/andris9/Nodemailer#attachments" rel="nofollow">attachment option in NodeMailer</a>:</p>
  
  <pre><code>{
    // stream as an attachment
    filename: 'text4.txt',
    content: fs.createReadStream('file.txt')
  }
  </code></pre>
  
  <p>I am able to create pdf and save it to a file in a directory and attach that saved file in the e-mail but <strong>I want to directly send the output of pdf to the attachment content of e-mail without saving the pdf output to a file</strong>.</p>
  
  <p>I tried to understand nodejs pipe and stream features but couldn't understand them to meet my requirement. I think it should be possible through stream and pipe but don't know how to achieve.</p>
  
  <p>I want to prevent saving of pdf output to file because there can be multiple users using the functionality of creating pdf file and sending e-mail. There can be a situation when a pdf file created by one user will be overwritten by another user.</p>