Please help my code doesn’t work on heroku but works on muylocal server

here is the link for the code

the error

at=info code=H81 desc=“Blank app” method=GET path="/" host=secret-coast-72065.herokuapp.com request_id=19d36b0e-5316-4a01-85f0-2f51fa8afaa9 fwd=“73.93.154.127” dyno= connect= service= status=502 bytes= protocol=https

This means that you have an internal server error. Most often, in my experience, this is caused by an issue between the application server and database.

However, there is not enough information here to help you.

Could you please describe:

  1. What does this application do?
  2. What language is it written in, and which services (if any) does it connect to?

i am not using a database it is a web using javascript that sends an email to order food, also the full code in the link above and the JS code here below

const express = require(“express”);
const app = express();
const bodyParser = require(“body-Parser”);
const nodemailer = require(“nodemailer”);
var exphbs = require(‘express-handlebars’);
app.engine(‘handlebars’, exphbs());
app.set(‘view engine’, ‘handlebars’);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(“public”));

app.get("/menu", function(req, res) {
res.sendFile(__dirname + ("/menu.html"));
})

app.get("/", function(req, res) {
res.sendFile(__dirname + ("/index.html"));
})

app.get("/success", function(req, res) {
res.sendFile(__dirname + ("/success.html"));
})

app.get("/views/order", function(req, res) {
res.render(__dirname + ("/views/order.ejs"));
})

app.post("/order", function(req, res) {

const output = `
<h1>لديك طلب جديد </h1>
<ul>  
  <h3>الاسم: ${req.body.name}</h3>
  <h3>رقم الهاتف: ${req.body.phone}</h3>
  <h3>العنوان: ${req.body.address}</h3>
</ul>
<h3>الطلب</h3>
<h1>${req.body.details}</h1>

`;

var transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: "Zaid.alkhatib97@gmail.com", // generated ethereal user
        pass: ""
    }
});

var mailOptions = {
    from: 'Zaid.alkhatib97@gmail.com',
    to: 'zalkhatib@mail.sfsu.edu',
    subject: 'Sending Email using Node.js',
    html: output
        // html: '<h1>Hi Smartherd</h1><p>Your Messsage</p>'        
};

transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
        console.log(error);
        res.render(__dirname + ("/views/failed.ejs"), { msg: "email sent" });


    } else {
        console.log('Email sent: ' + info.response);
        res.render(__dirname + ("/views/success.ejs"), { msg: "email sent" });
    }

});

});

app.set(‘port’, (process.env.PORT || 5000));

// Start node server
app.listen(app.get(‘port’), function() {
console.log('Node server is running on port ’ + app.get(‘port’));
});

thanks man, it is working now. i was a small issue issue it was body-Parser instead of bpdy-parser

1 Like

Glad to hear you figured it out. Typos are the #1 cause of bugs.

For future reference, try to format your code using markdown so that its easier to read on here.

You can do this with the “```” characters or by clicking the “</>” button in the editor to make your text preformatted.

1 Like

now i have another issue , on my local host , the email gets send normally but on the heroku. it takes to the filled page, can you take a lot at it
app.post("/order", function(req, res) {

const output = `
<h1>لديك طلب جديد </h1>
<ul>  
  <h3>الاسم: ${req.body.name}</h3>
  <h3>رقم الهاتف: ${req.body.phone}</h3>
  <h3>العنوان: ${req.body.address}</h3>
</ul>
<h3>الطلب</h3>
<h1>${req.body.details}</h1>

`;

var transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: "Zaid.alkhatib97@gmail.com", // generated ethereal user
        pass: ""
    }
});

var mailOptions = {
    from: 'Zaid.alkhatib97@gmail.com',
    to: 'zalkhatib@mail.sfsu.edu',
    subject: 'Sending Email using Node.js',
    html: output
        // html: '<h1>Hi Smartherd</h1><p>Your Messsage</p>'        
};

transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
        console.log(error);
        res.render(__dirname + ("/views/failed.ejs"), { msg: "email sent" });


    } else {
        console.log('Email sent: ' + info.response);
        res.render(__dirname + ("/views/success.ejs"), { msg: "email sent" });
    }

});

});

What do you mean by filled page?

1 Like

i meant to say failed page, but never mind i got. I had to allow my website to access my gmail, security thing basically! thank you!

1 Like

Glad it worked out for you.