Reputation: 1298
I have tried to find the answer for this already but even if I use the response for similar issues it won't work.
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: '[email protected]',
pass: '###'
}
}));
app.post('/send-email', function(req, res) {
var mailOptions = {
from: '"Naomi" <[email protected]>', // sender address
to: "[email protected]", // 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?
Upvotes: 0
Views: 1446
Reputation: 1598
Even if your app is working fine on your local machine doesn't guarantee that it will run on heroku as well.
In case heroku gives you an error of 'module not found', the first thing you should check if your package.json file.
Solution
If you find that your module is not present as dependency inside package.json than following the given steps
npm install <your missing package>
git add .
git commit -m "my fix"
git push heroku master
Note: you may update the push command according to your branch, in my case it was master.
Upvotes: 0
Reputation: 11311
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",
...
}
...
}
Upvotes: 1