0

I deployed my node.js app successfully to heroku however when I accessed the site there was an error saying "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch"

my code is

var router = require("./router.js");

// Create a web server
var http = require("http");

http.createServer(function (request, response) {
  router.home(request, response);
  router.user(request, response);
}).listen(1337);
console.log("Sever running at http://127.0.0.1:1337/");

I figured it has something to do with the port. There was a post similar to my problem Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch) but their solutions were based on Express. I didn't use express for my app. Is there any other way to not set the port to a fixed number?

Joji
  • 4,703
  • 7
  • 41
  • 86

1 Answers1

1

It doesn't matter if you use express or not. Herouku binds a port for you in the process.env.PORT environment variable. You need to use that like so:

var port = process.env.PORT || 1337

Then use .listen(port)
Make sure you're connecting to the correct port in your browser (log the port to console to be sure)

Evya
  • 2,325
  • 3
  • 11
  • 22