I'm trying to deploy a mern project for uni (already deplyoed react app on firebase) but my express/node.js rest api only works on localhost. I don't think the app even starts when deployed. Heroku gives me these errors:
Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
and error 503 service unavailable in the network tab.
I tried heroku logs --tail and it said heroku[router]: at=error code=H10 desc="App crashed" method=GET ...
my Procfile:
web: node index.js
my package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [
"heroku"
],
"engines": {
"node": "16.x"
},
"author": "me",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.14"
}
}
PORT variable in index.js:
const PORT = process.env.PORT || 5000;
...
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));
I used Heroku CLI to deploy the app:
git init
git add .
git commit -am "initial commit"
heroku git:remote -a {project-name}
git push heroku master