Skip to main content

Profile picture for Ajeet Raina
Author:
Ajeet Raina, Former Developer Growth Manager at Redis

How to build a NodeJS based application on Heroku using Redis

Step 1. Create Redis Enterprise Cloud

Create your free Redis Enterprise Cloud account. Follow this link to create Redis Enterprise Cloud subscription and database as shown below:

heroku

Save the database endpoint URL and password for future reference.

Step 2. Create a Heroku account

If you are using Heroku for the first time, create your new Heroku account through this link

heroku

Step 3. Install Heroku CLI on your system

 brew install heroku

Step 4. Login to Heroku

 heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/XXXXXXXXXXA
Logging in... done
Logged in as your_email_address

Step 5. Connect your application to Redis Enterprise Cloud

For this demonstration, we will be using a Sample Rate Limiting application

Clone the repository

 git clone https://github.com/redis-developer/basic-redis-rate-limiting-demo-nodejs

Run the below CLI to have a functioning Git repository that contains a simple application as well as a package.json file.

heroku create
Creating app... done, ⬢ rocky-lowlands-06306
https://rocky-lowlands-06306.herokuapp.com/ | https://git.heroku.com/rocky-lowlands-06306.git

Step 6. Setting up environment variables

Go to Heroku dashboard, click "Settings" and set REDIS_ENDPOINT_URI and REDIS_PASSWORD under the Config Vars. Refer to Step 1 for the reference.

heroku

You now have a functioning Git repository that contains a simple application as well as a package.json file, which is used by Node’s dependency manager.

Step 7. Deploy your code

$ git push heroku

Wait for few seconds and you will see the below messages being displayed:

remote: -----> Launching...
remote: Released v3
remote: https://rocky-lowlands-06306.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/rocky-lowlands-06306.git
* [new branch] main -> main

Step 8. Accessing the application

Open https://rocky-lowlands-06306.herokuapp.com/ to see your application

heroku

Next Steps