Search code examples
javascriptnode.jsherokupackage.jsonnodemailer

Heroku error: Cannot find module 'nodemailer-smtp-transport'


I have tried to find the answer for this already but even if I use the response for similar issues it won't work.

Full log on heroku enter image description here

enter image description here Here is my node.js code

var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
var nodemailer = require("nodemailer");
var smtpTransport = require('nodemailer-smtp-transport');

app.listen(process.env.PORT || 3000,function() {
    console.log("App is running" );
});




app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json());


/*app.listen(port, function() {
    console.log("App is running on port " + port);
});*/

var smtpTransport = nodemailer.createTransport(smtpTransport({
  service: 'Gmail',
  auth: {
    user: 'naomikudren@gmail.com',
    pass: '###'
  }
}));

app.post('/send-email', function(req, res) {
    var mailOptions = {
        from: '"Naomi" <naomikudren@gmail.com>', // sender address
        to: "naomikudren@gmail.com", // list of receivers
        subject: 'Request ', // Subject line
        text: "From: " + req.body.from + " To: " + req.body.to + " Date: " + req.body.date + " Time: " + req.body.time // plaintext body

    };
        smtpTransport.sendMail(mailOptions, function(error, info) {
         if (error) {
             return console.log(error);
         }
         console.log('Message sent: ' + info.response);
     });

     res.redirect("/index.html");
 });

Is there anything in my code that I am missing or what could be causing my server not to run?


Solution

  • As I pointed out in comments before, the error you mentioned is only the consequence of previously encountered error preventing your app from starting.

    (...) Boot timeout

    It basically means, that process starting your app has timed out because of different reason.

    In this case, it cannot find module nodemailer-smtp-transport, so all you need to do is to provide it as property of dependencies inside your package.json file and heroku should take care of the rest.

    {
        ...
        "dependencies": {
            ...
            "nodemailer-smtp-transport": "^2.7.4",
            ...
        }
        ...
    }