NodeJS - Deployment with heroku

In this article, I’ve added the steps which I’ve followed for deployment to heroku.

Step 1. Update your code as indicated below. Please insert code which takes port number dynamically from process.

const express = require('express');

const portFromProcess = process.env.PORT || 3000;

var app = express();

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

Step 2. Make sure you have git as version control system & all your changes are commited & pushed to origin.

Step 3. Run heroku login command to login to your heroku account. I assume you’ve heroku account.

sagar (master) node-web-server $ heroku login

Step 4. Run heroku keys:add command to add key. In my case, I selected

sagar (master) node-web-server $ heroku keys:add
? Which SSH key would you like to upload? (Use arrow keys)
❯ /Users/sagar/.ssh/ 

Step 5. To ensure, keys are added run following command

sagar (master) node-web-server $ heroku keys
heroku keys:remo=== keys
ssh-rsa AAAAB3NzaC...qOWnTlAw==

Step 6. Now run following command to set-up & authenticate with heroku.

sagar (master) node-web-server $ ssh -v

You should see output as follows. I’ve added last few lines of output here.

debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to ([]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LC_CTYPE = UTF-8
PTY allocation request failed on channel 0
shell request failed on channel 0

Step 7. Create heroku app.

heroku create

After executing above command, I got following output.

sagar (master) node-web-server $ heroku create
Creating app... done, ⬢ agile-retreat-76589 |

Step 8. Push/deploy your app to heroku.

git push heroku master

After executing above command, I got following output.

remote: -----> Compressing...
remote:        Done: 18.7M
remote: -----> Launching...
remote:        Released v3
remote: deployed to Heroku
remote: Verifying deploy... done.

Here is the output from heroku-admin-panel & website.