how to sending attachment when send mailer with nodejs code example

Example 1: send email nodejs

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '[email protected]',
    pass: 'yourpassword'
  }
});

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

Example 2: how to send attachments to node mailer file not found

function sendEmail(userEmail, htmlString, requestSnap, FIREBASE_WEB) {

fileName = "test.pdf";
folderName = "./" + uuid.v4();
mkdirp(folderName, function (err) {
    if (err) console.error(err)
    else console.log(folderName + ' folder created!')
});

pdf.create(htmlString + userEmail, options).toFile(folderName + '/' + fileName, function (err, res) { // if the file doesnt exist it will be created
    if (err) return console.log(err);
    console.log(res);

    var transporter = nodemailer.createTransport(smtpTransport({
        service: 'Gmail',
        auth: {
            user: '...',
            pass: '...'
        }
    }));
    console.log("\nPATH " + folderName + "/" + fileName);

    var mailOptions = {
        from: '[email protected]',
        to: userEmail,
        subject: 'So mail vo pdf-ot',
        text: 'Hellow',
        attachments: [{
            path: folderName + "/" + fileName
        }]
    };

    transporter.sendMail(mailOptions, function (error, info) {
        if (error) {
            console.log("ERROR kkkk " + error);
        } else {
            console.log('Email sent: ' + info.response);
            console.log("REQUEST SNAP " + JSON.stringify(requestSnap));
        }

        deleteFolderRecursive(folderName);
    });
});
}