The most updated documentation to get started with Heroku is the official Heroku Dev Center documentation.

Following is to get started with Node.js on Heroku

1. Install git and perform first time git setup

2. Install heroku cli

from here

3. Login in heroku using heroku cli

heroku login

On successful authentication, you get success message.

Logging in... done
Logged in as xxxxxxxx@xxxxx.com

Prepare the app

If dont already have the project in your local, clone it from your remote:

git clone https://github.com/heroku/node-js-getting-started.git
cd node-js-getting-started

Create an App on Heroku

you can either use the CLI or do it on Heroku UI.

Using CLI

$ heroku create
Creating sharp-rain-871... done, stack is heroku-18
http://sharp-rain-871.herokuapp.com/ | https://git.heroku.com/sharp-rain-871.git
Git remote heroku added

When you create an app, a git remote (called heroku) is also created and associated with your local git repository.

Heroku generates a random name (in this case sharp-rain-871) for your app, or you can pass a parameter to specify your own app name.

Using Heroku UI

Create from your Heroku Dashboard:

Deploy the app

$ git push heroku main

Note: If you did not use the heroku create on heroku cli, you may get the error:

$ git push heroku main
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.      

Please make sure you have the correct access rights
and the repository exists.

In such case, add the 2nd remote as heroku (get the URL for you app from Heroku website) (first remote is the GitHub remote) by:

$ git remote add heroku https://git.heroku.com/xxxx

You can check remotes now:

Deploy

git push heroku main 

should give logs like:

$ git push heroku main
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 4 threads
Compressing objects: 100% (23/23), done.
Writing objects: 100% (27/27), 12.46 KiB | 797.00 KiB/s, done.
Total 27 (delta 11), reused 3 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 16.x...
remote:        Downloading and installing node 16.15.0...
remote:        Using default npm version: 8.5.5
remote:
remote: -----> Installing dependencies
remote:        Installing node modules
remote:        added 78 packages, and audited 79 packages in 2s
remote:
remote:        19 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:
remote: -----> Build
remote:
remote: -----> Caching build
remote:        - node_modules
remote:
remote: -----> Pruning devDependencies
remote:
remote:        up to date, audited 79 packages in 447ms
remote:
remote:        19 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote:
remote: -----> Compressing...
remote:        Done: 32.5M
remote: -----> Launching...
remote:        Released v3
remote:        https://this-day8.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/this-day8.git
 * [new branch]      main -> main

But on visiting the URL I got error:

Check logs for troubleshooting

heroku logs –tail

Turns out nodemon was not found!

2022-05-06T09:58:26.000000+00:00 app[api]: Build succeeded
2022-05-06T09:58:27.023226+00:00 heroku[web.1]: Starting process with command `npm start`
2022-05-06T09:58:28.969211+00:00 app[web.1]:
2022-05-06T09:58:28.969223+00:00 app[web.1]: > testapifors@1.0.0 start
2022-05-06T09:58:28.969223+00:00 app[web.1]: > nodemon server.js
2022-05-06T09:58:28.969224+00:00 app[web.1]:
2022-05-06T09:58:28.974214+00:00 app[web.1]: sh: 1: nodemon: not found
2022-05-06T09:58:29.085724+00:00 heroku[web.1]: Process exited with status 127
2022-05-06T09:58:29.234553+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-06T09:58:29.251259+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-06T09:58:30.864850+00:00 heroku[web.1]: Starting process with command `npm start`
2022-05-06T09:58:32.548489+00:00 app[web.1]:
2022-05-06T09:58:32.548500+00:00 app[web.1]: > testapifors@1.0.0 start
2022-05-06T09:58:32.548500+00:00 app[web.1]: > nodemon server.js
2022-05-06T09:58:32.548500+00:00 app[web.1]:
2022-05-06T09:58:32.554184+00:00 app[web.1]: sh: 1: nodemon: not found
2022-05-06T09:58:32.671680+00:00 heroku[web.1]: Process exited with status 127
2022-05-06T09:58:32.851593+00:00 heroku[web.1]: State changed from starting to crashed

nodemon not found!

changed the package.json to not use nodemon, and use node instead, on npm start

Put nodemon in start.dev script in package.json

Retry:

..
..
2022-05-06T10:12:06.000000+00:00 app[api]: Build succeeded
2022-05-06T10:12:06.034850+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-06T10:12:07.725643+00:00 heroku[web.1]: Starting process with command `npm start`
2022-05-06T10:12:09.567392+00:00 app[web.1]: 
2022-05-06T10:13:13.742775+00:00 app[web.1]: > node server.js
2022-05-06T10:13:13.742775+00:00 app[web.1]:
2022-05-06T10:13:13.934105+00:00 app[web.1]: Server started on port 3000
2022-05-06T10:14:07.870659+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/wiki/today" host=this-day8.herokuapp.com request_id=be0d1924-0259-46d1-8b71-79eb4ee86ae6 fwd="183.83.140.195" dyno= connect= service= status=503 bytes= protocol=https
2022-05-06T10:14:10.927180+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-05-06T10:14:10.958959+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-05-06T10:14:11.227878+00:00 heroku[web.1]: Process exited with status 137
2022-05-06T10:14:11.278031+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-06T10:14:11.718507+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/wiki/today" host=this-day8.herokuapp.com request_id=6ac67c9b-a0df-4c51-8c09-6ceaee4e30f7 fwd="183.83.140.195" dyno= connect= service= status=503 bytes= protocol=https
2022-05-06T10:14:12.789253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/wiki/today" host=this-day8.herokuapp.com request_id=71d9a0f5-84cc-49d4-822a-280f47d0f17d fwd="183.83.140.195" dyno= connect= service= status=503 bytes= protocol=https

Notice Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Just starting your express server at process.env.PORT fixes this. Heroku automatically assigns a port that can be used by referencing process.env.PORT

See this SO answer for more.