Christopher
Christopher

Reputation: 315

node.js app getting the R10 error on Heroku

I have previously looked into similar questions but non of the solutions worked out for me which is why I am asking this question. I am simply trying to deploy my node.js application to heroku but I keep getting an application error.

the following is a part of my logs:

2018-09-29T18:54:45.545079+00:00 app[web.1]: > [email protected] start /app
2018-09-29T18:54:45.545081+00:00 app[web.1]: > node server.js
2018-09-29T18:54:45.545082+00:00 app[web.1]:
2018-09-29T18:54:46.035221+00:00 app[web.1]: listening to requests...
2018-09-29T18:55:43.134627+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-09-29T18:55:43.134859+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-09-29T18:55:43.317846+00:00 heroku[web.1]: Process exited with status 137
2018-09-29T18:55:43.329780+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-29T21:23:23.635112+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=project-gorilla-backend.herokuapp.com request_id=2ec25806-0c83-4a7d-9bd8-eab41a67e996 fwd="131.227.39.211" dyno= connect= service= status=503 bytes= protocol=https
2018-09-29T21:23:24.637219+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=project-gorilla-backend.herokuapp.com request_id=a0582179-52fe-4c55-ba87-b0c146d66962 fwd="131.227.39.211" dyno= connect= service= status=503 bytes= protocol=https

The following is my package.json file:

{
  "name": "pg_backend",
  "version": "1.0.0",
  "description": "back end application for the project gorilla site",
  "main": "index.js",
  "scripts": {
    "start": "node server.js"
  },
  "engines": {
    "node": "8.10.0",
    "npm": "5.6.0"
    },
  "author": "Christopher Salay",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3",
    "nodemailer": "^4.6.8",
    "socket.io": "^2.1.1",
    "vimeo": "^2.1.0"
  }
}

and this is my Procfile:

web: node server.js

the following is my server.js

let express = require('express'), app = express(), path = require('path'),
socket = require('socket.io'), emailModule = require('./email.js'), 
formValidationModule = require('./formValidation.js'), vimeoModule = require('./vimeo.js'),
port = process.env.PORT || 5000;

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

let server = app.listen(port,'0.0.0.0',function(){
    console.log('listening to requests...');
    vimeoModule.search()
});

let io = socket(server);


io.on('connection', (socket)=>{
    console.log('made a connection!');

    socket.on('email', (data)=>{
        if(formValidationModule.checkEmptyContact(data.client, data.email, data.name, 
            data.title, data.message)){
                socket.emit('invalidData');
            }
            else {
            /**
                 * * Here you need to set your email options which includes the clients email, destination email,
                 * subject and the text (the email content).
                 */
                emailModule.setMailOptions(data.email,/*'[email protected]'*/'[email protected]'
                , data.client + ' ' + '(' +
                data.name + ')' + ' ' + data.title, data.message).then((mailOpts)=>{
                    emailModule.send(mailOpts)

                });
                console.log('email has been sent!');
            }
    });
});

link to the heroku app:

https://pg-gorilla-backend.herokuapp.com/

and I use the following command to deploy to heroku:

git push heroku master

Upvotes: 0

Views: 735

Answers (1)

Piyush Jain
Piyush Jain

Reputation: 185

You need to configure your port on heroku as you cannot pass static port to the app when deploying to heroku, Heroku has built in method to bind designated port to app which is deployed on its environment. You need to use env var to assign port to the app. In heroku app you can do this by going through Settings > Show config vars > Add PORT 3000 in it and then heroku in built method will assign designated PORT number to the app.

Upvotes: 1

Related Questions