10

I've written a basic node.js application and I've managed to deploy it on Heroku without having any problem. I've created my package.json and Procfile, however from logs I see that there is no running processes, thus cannot get any response. What could be the problem?

PS: I do not want to use the Express framework

My Code:

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();

  console.log("I am working");
}).listen(8888);

My package.json:

{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
  },
  "engines": {
    "node": "0.8.x",
    "npm": "1.1.x"
  }
}

Logs:

2012-10-22T12:36:58+00:00 heroku[slugc]: Slug compilation started
2012-10-22T12:37:07+00:00 heroku[slugc]: Slug compilation finished
2012-10-22T12:40:55+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
2012-10-22T12:50:44+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
Ali
  • 5,338
  • 12
  • 55
  • 78

4 Answers4

38

Have you scaled the heroku app?

$ heroku ps:scale web=1

This is a required step. The 1 is the number of processes you want spawned for your app.

J. K.
  • 8,268
  • 1
  • 36
  • 35
  • 1
    You can also do this in the Heroku Dashboard by going to the app's Resources page and making sure you have at least 1 Dyno allocated. (In addition the port listening problem often comes next: http://stackoverflow.com/a/13013189/1310765). – purgatory101 Apr 12 '14 at 04:29
  • 1
    This just ended 30 minutes of frustration. Thank you :) – connorbode Jun 19 '14 at 17:14
  • This didn’t work for me, but one more step did, see http://stackoverflow.com/a/34749183/537998 – Kirk Strobeck Apr 04 '16 at 17:59
  • 1
    This ended 2 hour frustration for me... Thanks – Saras Arya Aug 14 '16 at 11:41
  • Is this the same for a Python app? Calculations that call Biopython methods don't seem to be working on Heroku, only the API calls I make to a remote database work. – mLstudent33 Jun 09 '21 at 19:32
26

Change your port

from

.listen(8888)

to

.listen(process.env.PORT || 8888)
jwchang
  • 10,584
  • 15
  • 58
  • 89
  • 1
    I run the node platform at Heroku. Ironically, this lowest answer is correct. The accepted and highest-voted answer will help only if you've previously scaled your web process to zero, and it will not fix the issue unless this answer is also followed. – hunterloftis Dec 31 '16 at 03:39
  • 1
    This needs to be the accepted answer. The ps:scale web was given in Heroku's documentation and thus, is a basic step. But this answer here was not given anywhere and is most likely causing the problem for a lot of people (including me) – Maude Aug 30 '18 at 01:08
3

What's inside your Procfile? Does it match your app name?

$ ls
app.js Procfile
$ cat Procfile
web: node app$
$
red
  • 3,163
  • 1
  • 17
  • 16
2

Things I had to do (didn't have to scale or use Express)..

  1. Create a Procfile in the root directory (a file literally called Procfile, no extension).
    Inside Procfile, type:

    web: node server.js
    
  2. Add a script and engine to package.json

    "scripts": {
            "start": "node server.js"
    }
    
    "engines": {
            "node": "8.9.3"
    }
    
  3. Update port in server.js

    var port = process.env.PORT || 8080;
    

And why..

  1. To explicitly declare what command should be executed to start your app. Heroku looks for a Procfile specifying your process types

  2. For the script, if no Procfile is present in the root directory during the build process, your web process will be started by running npm start. For the engine, to specify a Node version that matches the runtime you’re developing with and want to use on Heroku.

  3. Heroku already assigns your app a port and adds it to the env, so you can't set the port to a fixed number.

Resources:

https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

https://devcenter.heroku.com/articles/troubleshooting-node-deploys

https://devcenter.heroku.com/articles/deploying-nodejs

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Still not working for me. Locally all works fine via ```nodemon``` while in heroku nothing is opening I get those darn 503 all the time. – HX_unbanned Aug 28 '19 at 15:09