I have this simple web-server named index.js
:
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.get('/data', (req, res) => { res.send('Data') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
I added the Procfile
:
web:node server.js
I added the engines in my package.js
:
{ "name": "server", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1", "start": "nodemon ./index.js" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.17.3", "nodemon": "^2.0.15" }, "engines": { "node": "16.13.1", "npm": "8.1.2" } }
My deployment keeps failing with my heroku logs --tail
being the following:
2022-03-04T09:10:22.196622+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sismographie-back.herokuapp.com request_id=13ad01a2-0ff4-469e-820e-d61a337014e0 fwd="92.184.123.97" dyno= connect= service= status=503 bytes= protocol=https 2022-03-04T09:10:22.764644+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sismographie-back.herokuapp.com request_id=09b110c3-0b16-45c0-8c02-02c77a7907c0 fwd="92.184.123.97" dyno= connect= service= status=503 bytes= protocol=http
If this matters, I’m using the /Deploy > Deploy Branch built-in feature.
What is happening?
Thanks.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You cannot use 3000 as your default port on heroku.You should use heroku’s port.The problem is basically arising due to the port.
For working of it change your code like –
app.listen(process.env.PORT || port, () => { console.log(`Example app listening on port ${port}`) });
Now heroku will pick a random port based on their server and if they can’t fetch any your port will have presendence over it.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0