Heroku Application Error

Hi guys, I keep getting this error every time I deployed my application and i was hoping someone can help me figure out what I’m doing wrong.

2020-08-28T14:09:51.552571+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=calm-brook-00562.herokuapp.com request_id=05fccd31-cb54-4be6-8162-41466b7842ee fwd=“” dyno= connect= service= status=503 bytes= protocol=https 2020-08-28T14:09:52.470253+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" host=calm-brook-00562.herokuapp.com request_id=4c199457-38cf-47be-8e4b-e669ba8791a6 fwd=“” dyno= connect= service= status=503 bytes= protocol=https

const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
const path = require('path');

app.use(bodyParser.urlencoded({extended: true}));

app.post('/contact', (req, res) => {
  nodemailer.createTestAccount((err, account) =>{
    const output = `
    <h3>Contact Detail</h3>
      <li>Name: ${req.body.name}</li>
      <li>Email: ${req.body.email}</li>
      <li>Subject: ${req.body.subject}</li>

    // Step 1
    let transporter = nodemailer.createTransport({
      service: 'gmail',
      port: 465,
      secure: true, // use SSL
      auth: {
        user: 'xxx', // generated ethereal user
        pass: 'xxxx' // generated ethereal password
        rejectUnauthorized: false

       //  Step 2
       let mailOptions = {
         from: "rogerw213@gmail.com", // sender address
         to: "bojurier@gmail.com", // list of receivers
         subject: "New Message", // Subject line
         text: req.body.message,
         html: output // html body
      //  Step 3

      transporter.sendMail(mailOptions, (err, info) => {
        if (err) {
        } else {
          console.log('Email Sent!!!')

        console.log('Message Sent: ' + info.message)
        console.log('Message URL:' + nodemailer.getTestMessageUrl(info))
// Serve staic assets if in production
if(process.env.NODE_ENV ==='production') {
  // set a static folder

  app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'my-app', 'build', 'index.html'));

app.listen(process.env.PORT || 5000, function () {
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);

Is there more to your code? Is it available on GitHub as an Open Source Software? Probably needs more digging into what’s going wrong. Based on the 503 status code, it’s a server side error. I also went to the site calm-brook-00562.herokuapp.com , no HTML page was coming up.

In terms of backend code, one thing I noticed was, the response variable was not used, not sure if express framework handles that

Another thing that I noticed was the errors were not handled in the nodemailer.createTestAccount() callback function

And I tried the code locally and the static file serving worked for me with a simple index.html - I put the code here - https://github.com/karuppiah7890/issues-info/tree/main/freecodecamp-forum/heroku-error/418059 . Not sure how the static file serving is not working for you. Do you have the my-app/build/ directory in the code?

Thank you so much, this is my code on Github. My code works well my issue is, whenever I deploy it on Heroku it tells me it build successfully and everything is complete, but when I go to on look at my page on Heroku it tells me Application Error to check heroku cli log. Also, I do not have a build/my-app because I set it to build when the application is deployed

“name”: “backend”,
“version”: “1.0.0”,
“description”: “Bojurie Rogers Portfolio”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”,
“server”: “nodemon server.js”,
“client”: “npm start --prefix client”,
“dev”: “concurrently “npm run server”“npm run client””,
“heroku-postbuild”: “NPM_CONFIG_PRODUCTION=false npm install --prefix my-app && npm run build --prefix my-app”

It’s late now. I’ll check code tomorrow maybe and get back!

1 Like

@Bojurie In the github code, I don’t see the package.json content you have mentioned above. Is that the only change? The package.json ?

its in the server.js and i’m trying to push it to GitHub but i’m having a hard time doing so because the frontend react app and the backend nodejs/expressjs are in 2 separate folders.

Ah. Maybe something to checkout is, how to deploy both in the same Heroku application, with code in the same repo, or as two separate Heroku applications, with code maybe in different git repos

1 Like

ok i have added the server into my application, however i’m still getting the error

1 Like

Okay, I’ll have to spend some time debugging tomorrow morning. Will get back :sweat_smile:

1 Like

Hey, how are you doing? Did you have any luck on why it’s showing my page after I deploy it on Heroku?

No, I couldn’t debug it later.