Application Error on new Heroku app - node.js

I know this question has been answered a lot, but I still can't figure out a solution to my problem. I've created a little app which is supposed to work with the Slack webhook. Locally, it works just fine - I use node app in order to launch it.
I've created my app on Heroku, pushed my files (Procfile app.js hellobot.js package.json)
But when I visit http://slackbot2.herokuapp.com/, I get an Application Error message.
I already tried the log but I get this :
2015-06-11T23:39:05.967607+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slackbot2.herokuapp.com request_id=b3783c70-306b-4528-9d81-4e8ab43e9132 fwd="*******" dyno= connect= service= status=503 bytes=
This heroku run rails console and heroku run rake db:migrate won't work. bash: rails command not found. Rails and Rake are installed on my Mac (OSX 10.10.4). Those were the only solutions that worked for others .. But not me.

Same thing happened with me. As far as I can remember, the reason for this is the port you used in the application. Heroku will not run your app on port 8080 or 3000, instead it will be some random port. Use this code to fix the problem.
var port = process.env.PORT || 8080;
Use this code to start the server.
app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});

Related

Node Express server works in Heroku staging pipeline but not on production pipeline (no such app error)

I developed an api with nodejs, express and run (npm start) with pm2 (link). I published the app on heroku in a pipeline, I use the staging and production pipeline. The staging app works fine, but the production app is very inconsistent, succeeding sometimes and failing most.
Below the api access log, in the second request there is an error 404 with "no such app" in the html body error message (it is not in the image log).
2021-11-22T12:52:37.266486+00:00 app[web.1]: Starting server in port 12080
2021-11-22T12:52:37.567394+00:00 heroku[router]: at=info method=POST path="/token" host={hidden}-production.herokuapp.com request_id={hidden} fwd="{hidden}" dyno=web.1ect=0ms service=692ms status=200 bytes=613 protocol=https
2021-11-22T12:53:12.688593+00:00 heroku[router]: at=info method=POST path="/token" host={hidden}-production.herokuapp.com request_id={hidden} fwd="{hidden}" dyno=web.1 connect=0ms service=35ms status=404 bytes=711 protocol=https
I believe it is not a route problem, it works sometimes and in staging it works fine. I'm using Heroku's promotion button (staging -> production).
Is there a problem with Heroku?
Are any different configurations required for the application in production?
The problem was in my app syncing with the Heroku routers.
Was fixed by the Heroku team itself.

How do I use http2 with Node on Heroku (using Koa)

I have the following code...
const PORT = process.env.PORT || 5000;
const app = new Koa();
...
app.listen(PORT)
This works great both locally and in Heroku. So now I want to use Http2 so I change to the following...
const server = http2.createSecureServer(
{
"key": fs.readFileSync('./server-key.pem'),
"cert": fs.readFileSync('./server-cert.pem')
},
app.callback()
)
server.listen(PORT);
This works ok locally, however, when I upload to Heroku I get...
2021-06-24T00:43:00.383108+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=my-app.herokuapp.com request_id=604f4a2c-8dd2-4cfa-9cf2-3cce5ef76070 fwd="..." dyno=web.1 connect=0ms service=1ms status=503 bytes=0 protocol=https
So how do I get http2 working with Node, Koa, and Heroku?
Per this article on devcenter.heroku.com, Heroku does not yet support http/2.
You can use an add-on like https://elements.heroku.com/addons/expeditedwaf or you can use cloudflare. If you decide to use cloudflare, make sure you add a SSL certificate between cloudflare and heroku.
Alternatively have a look at https://elements.heroku.com/addons/expeditedcdn.
It should be way cheaper than the full blown Web App Firewall.

Heroku App rollback works but identical code does not - works perfectly locally

I have a Node.js app running a React front-end hosted on Heroku which is linked to a Github repository so that on push it redeploys the app. I have been using the app this way without problem for around a year now.
It works on Heroku Local, and running the node app locally without Heroku but I'm getting a 503 service unavailable error when I run a put request when running the app online.
2021-06-01T08:04:27.326913+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=PUT path="/api/auth/login" host=myapp.herokuapp.com request_id=9b84f5c5-def4-4dce-82d2-baf1bef3a9a8 fwd="90.215.204.78" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
Any pointers?
It was fixed by adding a Procfile with: "web:server/index.js" as well as specifying the Node version specifically changing the code in my package.json from:
"engine":"12.x",
to:
"engines": {
"node":"v12.18.3"
},
I think it is likely the package.json change that ultimately fixed the problem.

code=H10 desc="App crashed" method=GET path="/", trying to upload my project on heroku

So, I have successfully uploaded my whole project(angular + node files) on heroku, I have also uploaded my mongodb database on mlab. But my app always gets crashed.
Here is the heroku log:
I have already tried changing ports to--> log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router)), it seems to work for most of them but not for me.
I have also removed engine section from package.json. Still no luck. Any help would be really appreciated.

Heroku + node.js error at=error code=H10 desc="App crashed" method=GET path="/"

I'm building a simple app, it works when 100% local, it works on heroku with local, when I try to access from heroku it crashes. I get this error
at=error code=H10 desc="App crashed" method=GET path="/"
I tried a few things already
I change the harcoded port in my app.js to a process.env.PORT
I did heroku restart
I did most of the stuff people say about this issue on stackoverflow
But I still get the same error.
My code is on this plnkr
https://plnkr.co/edit/1nORDleC7pmFphEpXcGO
Also I have some issue with my .env file as it contain only this
using
cat .env
I get this
TIMES=2
How do I add stuff in it, I want to add 2 keys,
And if I have only this in my .env how does this app.listen know the port...
app.listen(process.env.PORT || 3000);
Edit : I have another hint, looking at the logs my process crashes right after it started. Like 2 seconds later.
So I
Heroku restart
I get
Starting process with command...
And immediately after I get
State changed from starting to crashed
Process exited with status 0
Why... :'(
Ok I got the issue !!
So in my Procfile I wrote
web : blablabla blablabla node app.js
And the issue was that I needed to delete the " : " before blablabla because the heroku console could't read it !
Now it works amazing !

Resources