{"id":2094,"date":"2022-08-30T15:22:00","date_gmt":"2022-08-30T15:22:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/25\/web-dynos-keep-crashing-while-trying-to-deploy-my-first-node-js-app-to-heroku-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:00","modified_gmt":"2022-08-30T15:22:00","slug":"web-dynos-keep-crashing-while-trying-to-deploy-my-first-node-js-app-to-heroku-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/web-dynos-keep-crashing-while-trying-to-deploy-my-first-node-js-app-to-heroku-collection-of-common-programming-errors\/","title":{"rendered":"Web dynos keep crashing while trying to deploy my first node.js app to Heroku-Collection of common programming errors"},"content":{"rendered":"<pre><code>$ foreman start\n<\/code><\/pre>\n<p>creates a link with my working app I have a file Called Procfile that contains:<\/p>\n<pre><code>web: node server.js\n<\/code><\/pre>\n<p>Here is my package.json<\/p>\n<pre><code>{\n  \"name\": \"node-example\",\n  \"version\": \"0.0.1\",\n  \"dependencies\": {\n    \"express\": \"3.1.0\",\n    \"jade\": \"*\",\n    \"socket.io\": \"*\",\n    \"underscore\": \"*\"\n  }\n}\n<\/code><\/pre>\n<p>So I go to start the &#8220;dynos&#8221; with<\/p>\n<pre><code> $ heroku ps:scale web=1\nScaling web dynos... done, now running 1\n\n\n$ heroku ps\n=== web (1X): `node server.js`\nweb.1: restarting 2013\/09\/27 22:10:44 (~ 34s ago)\n<\/code><\/pre>\n<p>a little later<\/p>\n<pre><code>$ heroku ps\n=== web (1X): `node server.js`\nweb.1: crashed 2013\/09\/27 22:11:49 (~ 10s ago)\n<\/code><\/pre>\n<p>Any ideas on where I go from here?<\/p>\n<p>EDIT: Here are some logs<\/p>\n<pre><code>2013-09-27T12:10:47.177359+00:00 heroku[web.1]: Starting process with command `node server.js`\n2013-09-27T12:10:48.381526+00:00 app[web.1]: Server up and running. Go to http:\/\/127.0.0.1:8080\n2013-09-27T12:10:48.342939+00:00 app[web.1]: info: socket.io started\n2013-09-27T12:11:48.499022+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web process failed to bind to $PORT within 60 seconds of launch\n2013-09-27T12:11:48.499325+00:00 heroku[web.1]: Stopping process with SIGKILL\n2013-09-27T12:11:49.656186+00:00 heroku[web.1]: State changed from starting to crashed\n2013-09-27T12:11:49.643225+00:00 heroku[web.1]: Process exited with status 137\n<\/code><\/pre>\n<p>EDI: server.js<\/p>\n<pre><code>var portx = process.env.PORT;  \/\/ This is my addition\n\nvar express = require(\"express\")\n  , app = express()\n  , http = require(\"http\").createServer(app)\n  , io = require(\"socket.io\").listen(http)\n  , _ = require(\"underscore\");\n\nvar participants = []\n\napp.set(\"ipaddr\", \"127.0.0.1\");\n\napp.set(\"port\", portx);  \/\/ to here\n\napp.set(\"views\", __dirname + \"\/views\");\napp.set(\"view engine\", \"jade\");\napp.use(express.static(\"public\", __dirname + \"\/public\"));\napp.use(express.bodyParser());\napp.get(\"\/\", function(request, response) {\n\n  response.render(\"index\");\n\n});\n\napp.post(\"\/message\", function(request, response) {\n\n  var message = request.body.message;\n\n  if(_.isUndefined(message) || _.isEmpty(message.trim())) {\n    return response.json(400, {error: \"Message is invalid\"});\n  }\n\n  var name = request.body.name;\n  io.sockets.emit(\"incomingMessage\", {message: message, name: name});\n  response.json(200, {message: \"Message received\"});\n});\n\nio.on(\"connection\", function(socket){\n\n  socket.on(\"newUser\", function(data) {\n    participants.push({id: data.id, name: data.name});\n    io.sockets.emit(\"newConnection\", {participants: participants});\n  });\n\n  socket.on(\"nameChange\", function(data) {\n    _.findWhere(participants, {id: socket.id}).name = data.name;\n    io.sockets.emit(\"nameChanged\", {id: data.id, name: data.name});\n  });\n\n  socket.on(\"disconnect\", function() {\n    participants = _.without(participants,_.findWhere(participants, {id: socket.id}));\n    io.sockets.emit(\"userDisconnected\", {id: socket.id, sender:\"system\"});\n  });\n\n});\n\nhttp.listen(app.get(\"port\"), app.get(\"ipaddr\"), function() {\n  console.log(\"Server up and running. Go to http:\/\/\" + app.get(\"ipaddr\") + \":\" + app.get(\"port\"));\n});\n<\/code><\/pre>\n<p>Now I get this similar error.<\/p>\n<pre><code>2013-09-28T02:38:51.301568+00:00 app[web.1]: info: socket.io started\n2013-09-28T02:38:51.363825+00:00 app[web.1]: Server up and running. Go to http:\/\/127.0.0.1:31707\n2013-09-28T02:39:50.974347+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web process failed to bind to $PORT within 60 seconds of launch\n2013-09-28T02:39:50.974557+00:00 heroku[web.1]: Stopping process with SIGKILL\n2013-09-28T02:39:52.927176+00:00 heroku[web.1]: Process exited with status 137\n2013-09-28T02:39:52.945829+00:00 heroku[web.1]: State changed from starting to crashed\n<\/code><\/pre>\n<ol>\n<li>\n<p>I can&#8217;t be sure without the Node code where you create the server, however from the logs it looks like you are not listening on the correct port.<\/p>\n<p>Heroku assigns your application a port (which is set as the &#8220;PORT&#8221; environment variable) that your application must listen on. If you do not connect to this port within 60s, it will kill your app, and this seems to be what is happening.<\/p>\n<p>UPDATE: In fact, based on your web.1 log entry, it looks like you are trying to listen on port 8080. I think it is highly unlikely that this is the port provided by Heroku. You can get the port Heroku provides from process.env.PORT, and then listen on that.<\/p>\n<\/li>\n<li>\n<p>try looking in your dashboard check that you have at least one Dynos. It&#8217;s happen to me that I add more than one app and I use the free trail so it keep moving the Dyno between the app.<\/p>\n<p>Good Luck.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-12-25 11:07:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>$ foreman start creates a link with my working app I have a file Called Procfile that contains: web: node server.js Here is my package.json { &#8220;name&#8221;: &#8220;node-example&#8221;, &#8220;version&#8221;: &#8220;0.0.1&#8221;, &#8220;dependencies&#8221;: { &#8220;express&#8221;: &#8220;3.1.0&#8221;, &#8220;jade&#8221;: &#8220;*&#8221;, &#8220;socket.io&#8221;: &#8220;*&#8221;, &#8220;underscore&#8221;: &#8220;*&#8221; } } So I go to start the &#8220;dynos&#8221; with $ heroku ps:scale web=1 Scaling [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2094","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2094"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2094\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}