Host and Use Redis for Free
Tags: javascript, tutorial, redis, node
Published: 2021-04-21 01:22:31

_This article was originally posted on [Medium](https://medium.com/swlh/host-and-use-redis-for-free-b70d65a13edd). If you prefer reading it from there, please do check it out._

## Introduction

Although building software projects can be challenging, deployment can be a pain. 

In fact, in situations where speed is necessary, deployment must be seamless. For that reason, I want to show you how to deploy Redis for free and use Redis remotely. 

[Redis Labs](https://redislabs.com/), a Redis cloud hosting service, offers a free plan with simple deployment steps. We will leverage that plan to create an instance and integrate that instance with Node.js.

## Walk Through
> Do everything quickly and well.
> ― G.I. Gurdjieff

To start, head over to [https://redislabs.com/](https://redislabs.com/) and sign up.

![Photo by Author](https://cdn-images-1.medium.com/max/3796/1*wErfShGOjlbPVbnTmvDCrA.png)

Once you create and verify your account, you will end up on this screen.

![Photo by Author](https://cdn-images-1.medium.com/max/3840/1*8tEXz40I048vjI9P0WXuBA.png)

Click “Create your subscription”.

![](https://cdn-images-1.medium.com/max/3804/1*9s4XRGY6NGnvH-Dcmn_z9w.png)

Scroll down to “Fixed size” and pick the free option.

![Photo by Author](https://cdn-images-1.medium.com/max/3798/1*ZJae6g3-D98R0n7cZ8lS0g.png)

Click “Create”. We now need to create our database under the subscription.

![Photo by Author](https://cdn-images-1.medium.com/max/3810/1*MiFD4JsIghT7Q0ZWI_KSVA.png)

Enter in the database name. Be sure to copy “Redis Password”. Once you are ready, click “Activate”.

![Photo by Author](https://cdn-images-1.medium.com/max/3796/1*ujM1mWiIt2UuHuTuzxg2dA.png)

We can use the endpoint to connect to our remote instance so be sure to copy it down. For security reasons, be careful with who you expose your endpoint to.

 <iframe src="https://medium.com/media/4537c9bd9b809c0494d4abdca06eb145" frameborder=0></iframe>

**It is really that quick!**

## Integration

Let’s connect to our remote Redis instance! Although I will use Node.js, the connection process will most likely be similar to the other technologies.

Start by creating a new npm project.

    npm init

After filling out the project details, cd into your project and install [redis](https://redis.js.org/), a Node.js client for Redis, and [dotenv](https://www.npmjs.com/package/dotenv), an environment variable loader.

    npm install redis

    npm install dotenv --save-dev

In the root directory, create a file called `.env` . In it, let’s put our Redis instance hostname, port, and password.

*We can find the hostname, port, and password in the View Database section:*

![Photo by Author](https://cdn-images-1.medium.com/max/2636/1*ynXHj7nEJLLnEOxXq7OSrg.png)

Contents of `.env`:

```javascript
    REDIS_HOSTNAME=YOUR REDIS HOSTNAME
    REDIS_PORT=YOUR REDIS PORT
    REDIS_PASSWORD=YOUR REDIS PASSWORD
```
Create `index.js`. Let’s say this is where we want to connect to our remote instance. Let’s create a client and test if we can connect to it.

{% gist
https://gist.github.com/Ramko9999/39dc0ed35bf5bbce7c6fc02eec78fbc1

%}

**Now we can connect to our Redis instance from Node.js!**

 <iframe src="https://medium.com/media/28da9e73abae1487772293252601e35c" frameborder=0></iframe>

## Conclusion

I wanted to show a simple way to deploy and use Redis for free, whether it be for demoing a project at a hackathon or evaluating a proof of concept idea.

**Thank you for taking the time to read this blog!**