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?

1
  • Try to bind to process.env.PORT rather than port 1337. PORT is an environment variable that Heroku sets for you. Commented Feb 25, 2018 at 19:06

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.