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”
- I can´t install nodemon globally, “nodemon” not recognized
- Cp: target is not a directory
- How can I update npm itself?
- How to install a previous exact version of a NPM package?
- What is the file node.exe for?
- Discord API error when trying to send one command at discord using JavaScript client
- Client on Node.js: Uncaught ReferenceError: require is not defined
- What is this JavaScript “require”?
- How do I resolve “Cannot find module” error using Node.js?
- Node.js heap out of memory
- await is only valid in async function
- How to set NODE_ENV to production/development in OS X
- env: node: No such file or directory in mac
- Error: unable to verify the first certificate in nodejs
- nodemon – app crashed – waiting for file changes before starting
- How to obtain username from Promise
? - how to use CryptoJS in javascript
- Node.js – SyntaxError: Unexpected token import
- nodemon not found in npm
- How can I wait In Node.js (JavaScript)? l need to pause for a period of time
- How to change to an older version of Node.js
- npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
- Why am I getting “Error socket hang up” response?
- Error: EACCES: permission denied
- ReferenceError : window is not defined at object.
Node.js - What does the ELIFECYCLE Node.js error mean?
- Node.js Port 3000 already in use but it actually isn’t?
- Bundler: You must use Bundler 2 or greater with this lockfile
- How to Create and Use Enum in Mongoose
- Unable to verify leaf signature
- How to write a .nvmrc file which automatically change node version
- node.js: how to use setInterval and clearInterval?
- AJAX response error: net::ERR_EMPTY_RESPONSE
- Git Bash Command on Windows, yarn command not found
- ‘npm’ is not recognized as internal or external command, operable program or batch file
- TypeError: app.use() requires middleware functions
- What is process.env.PORT in Node.js?
- Cannot find module ‘internal/util/types’
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- I am getting error in console “You need to enable JavaScript to run this app.” reactjs
- How is JavaScript .on() method defined?
- Node.js document is not defined
- Passport and connect-flash: req.flash is not a function
- Push items into mongo array via mongoose
- Error: Cannot find module ‘webpack’
- E11000 duplicate key error index in mongodb mongoose
- Node.js: Difference between req.query[] and req.params
- sequelize “findbyid” is not a function but apparently “findAll” is
- What is the difference between node.js and io.js?
- module.exports vs exports in Node.js
- Npm install cannot find module ‘semver’
- How to download a file with Node.js (without using third-party libraries)?
- How do I remove documents using Node.js Mongoose?
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- How to Reinstall Broken npm
- What is javascript runtime..?
- Block-scoped declarations not yet supported outside strict mode
- ‘gulp’ is not recognized as an internal or external command
- No gulpfile found
- How is req.isAuthenticated() in Passport JS implemented?
- Cannot npm install due to node-gyp: binding.gyp not found
- Downgrade npm to an older version
- How do I fix the npm UNMET PEER DEPENDENCY warning?
- TypeError: res.json is not a function
- How to fix error “ERROR: Command errored out with exit status 1: python.” when trying to install django-heroku using pip
- Eslint: How to disable “unexpected console statement” in Node.js?
- H14 error in heroku – “no web processes running”
- TypeError: callback is not a function in nodejs
- How to create a directory if it doesn’t exist using Node.js
- heroku open – no app specified
- npm “failed to parse json”
- Npm Error – Windows NT – How to resolve
- How to update a array value in Mongoose
- How to sort a collection by date in MongoDB?
- How to sort in mongoose?
- failed to push some refs to [email protected]
- npm install with error: `gyp` failed with exit code: 1
- npm update check failed
- How to convert binary string to decimal?
- Forwarding port 80 to 8080 using NGINX
- Configure Node.js to log to a file instead of the console
- “React.Children.only expected to receive a single React element child” error when putting
and in a - How to fix “TypeError: Right-hand side of ‘instanceof’ is not callable” when I use another module class?
- how to add inside a text box?
- DeprecationWarning: Calling an asynchronous function without callback is deprecated. – how to find where the “function:” is?
- Problem when embedding images on Discord Webhook (Image hosted on a WordPress website)
- How do you install Node.JS on CentOS?