Heroku dynamically assigns your app a port, so you can’t set the port to a fixed number. Heroku adds the port to the env, so you can pull it from there. Switch your listen to this:
.listen(process.env.PORT || 5000)
That way it’ll still listen to port 5000 when you test locally, but it will also work on Heroku.
You can check out the Heroku docs on Node.js here.
Related Posts:
- npm ERR cb() never called
- Heroku: “No default language could be detected for this app” error thrown for node app
- Heroku: “No default language could be detected for this app” error thrown for node app
- Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
- Getting “Warning: unprotected private key file!” error message while attempting to import SSH key
- First Heroku deploy failed `error code=H10`
- What is Procfile? and Web and Worker
- What is Procfile? and Web and Worker
- Heroku giving 500 error with little information + Internal Server Error
- First Heroku deploy failed `error code=H10`
- heroku is giving me Method not allowed
- Heroku: Your account has reached its concurrent build limit
- Heroku “State changed from starting to down Stopping all processes with SIGTERM”
- How to make a discord bot create an invite for every server it joins?
- map function for objects (instead of arrays)
- I can´t install nodemon globally, “nodemon” not recognized
- Cp: target is not a directory
- How can I update NodeJS and NPM to the next versions?
- How can I update npm itself?
- How do I update Node.js?
- How to install a previous exact version of a NPM package?
- How to fix ‘Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.’
- How to fix ‘Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.’
- How to solve npm error “npm ERR! code ELIFECYCLE”
- Start script missing error when running npm start
- How to solve npm error “npm ERR! code ELIFECYCLE”
- npm check and update package if needed
- What is the file node.exe for?
- Node.js version on the command line? (not the REPL)
- Can not find module “@angular-devkit/build-angular”
- Node.exe Stuck at 100% CPU
- After command npm start “Missing script:start” error
- sudo: npm: command not found
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]
- Discord API error when trying to send one command at discord using JavaScript client
- How to you store data for each discord user in the discord server?
- Upgrading Node.js to latest version
- How to resolve Nodejs: Error: ENOENT: no such file or directory
- bash: npm: command not found?
- Babel 6 regeneratorRuntime is not defined
- TypeError: Converting circular structure to JSON in nodejs
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- Node.js getaddrinfo ENOTFOUND
- How do I debug error ECONNRESET in Node.js?
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- Node.js getaddrinfo ENOTFOUND
- How do I debug error ECONNRESET in Node.js?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- How to fix “ReferenceError: primordials is not defined” in Node.js
- Does anyone knows what “rimraf” means?
- How can I completely uninstall nodejs, npm and node in Ubuntu [closed]
- Please run `npm cache clean`
- Client on Node.js: Uncaught ReferenceError: require is not defined
- What is this JavaScript “require”?
- Error: Can’t set headers after they are sent to the client
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- node.js string.replace doesn’t work?
- What is the difference between npm install and npm run build?
- require is not defined? Node.js
- Client on Node.js: Uncaught ReferenceError: require is not defined
- What is this JavaScript “require”?
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- What is “export default” in JavaScript?
- What is Express.js?
- Cannot GET / Nodejs Error
- How do I resolve “Cannot find module” error using Node.js?
- What is NODE_ENV and how to use it in Express?
- Node.js heap out of memory
- Missing write access in mac to /usr/local/lib/node_modules
- Reactjs – Form input validation
- What is the difference between __dirname and ./ in node.js?
- NPM clean modules
- ‘node’ is not recognized as an internal or an external command, operable program or batch file while using phonegap/cordova
- How can the default node version be set using NVM?
- await is only valid in async function
- What does body-parser do with express?
- “Cannot GET /” with Connect on Node.js
- How to set NODE_ENV to production/development in OS X
- How to enable CORS in flask
- await is only valid in async function
- node.js, Error: Cannot find module ‘express’
- nodemon app crashed – waiting for file changes before starting
- env: node: No such file or directory in mac
- mongoError: Topology was destroyed
- NPM Start not starting local server
- Error: unable to verify the first certificate in nodejs
- TypeError: Router.use() requires middleware function but got a Object
- node.js, Error: Cannot find module ‘express’
- nodemon – app crashed – waiting for file changes before starting
- What does the ELIFECYCLE Node.js error mean?
- “Topology was destroyed” when using MongoDB with native driver and Express.js
- What does “res.render” do, and what does the html file look like?
- How to obtain username from Promise
? - Error: getaddrinfo ENOTFOUND in nodejs for get call
- heroku: no default language could be detected for this app
- How do I resolve “Cannot find module” error using Node.js?
- NPM ELIFECYCLE error – using node server.js command