Heroku error H10 when deploying my Node.js app

Viewed 27

I've been working to deploy my app to Heroku but keep running into an H10 error. The app works locally but no luck deploying to Heroku.

Here is the index.js:

import express from 'express'
import 'dotenv/config'
import router from './routes/index.js'
import morgan from 'morgan'

const app = express()

const port = process.env.PORT || 5000

app.use('/public', express.static('public'))

app.use(express.urlencoded({ extended: false }))

app.use(express.json())

app.use(morgan('dev'))

app.use('/', router)

app.listen(process.env.PORT || port)

Here is my Procfile:

web: node index.js

Here is the package.json:

{
  "name": "node-sso-example-app",
  "version": "1.0.0",
  "description": "Example Node.js SSO App using WorkOS",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "WorkOS",
  "dependencies": {
    "express": "^4.18.1",
    "ejs": "^3.1.8",
    "router": "^1.3.7",
    "dotenv": "^16.0.1",
    "@workos-inc/node": "^2.11.0",
    "morgan": "^1.10.0",
    "cookie-parser": "^1.4.6",
    "express-session": "^1.17.2",
    "http-errors": "~1.6.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.19"
  },
  "engines": {
    "node": "^16.17.0"
  }
}

I'm stuck at this point and have read through what feels like every Stackoverflow question on this same error with no luck.

1 Answers

i'm new to nodejs and heroku but i was facing the same problem H10. It is probably related to ports. Try to remove this line completely

const port = process.env.PORT || 5000

and add this for index.js (I believe you can use any port and Heroku can manually allocate a different port

//start server
app.listen(process.env.PORT || 3000, function(){
    console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

Or keep const port, but use this instead:

app.listen(port, () => {
    console.log(`server started on port ${port}`);
})
Related