Terminal Chat Application using Serverless Redis

Rafael Nunes
Nov 12 · 3 min read

During coding or working on terminal many Developers/DevOps don’t want to switch Slack and don’t want to lost their focus. I was thinking about this problem and decided to implement a simple solution that can be helpful for small teams that can make a chat using terminal.

So in this blog post we will implement a Terminal Chat application using Serverless Redis and Bless.js. This application will be as simple as possible but according to feedbacks there might be improvements and new features. Please feel free to give a feedback to us!

                       npm i -g taalk
Image for post
Image for post
Taalk using Serverless Redis

Prerequisites

  • Basic javascript/nodejs knowledge
  • Basic Redis knowledge

Let’s take a quick look for our design:

Image for post
Image for post

All communication is handled by using Redis pub/sub channels. Every user will subscribe the same channel for incoming messages and all users will publish the messages to same channel.

We will have only 2 file for whole application and we will use Blessed.js and ioredis libraries.

Let’s start to implement chat application. In order to keep simplicity we will only get single argument which will be Redis url. You can get url from the Lambda Store Console with Connect button. Please select ioredis in the menu and you can get the url.

              taalk redis://:$your_redis_url

Note: If TLS is enabled your redis url should start with “rediss

In our index.js, we will check Redis Connection and ask to user for his name. This name will be used in Chat Room

Read the Redis URL from arguments and make initial connection

In above code snippet, we are reading Redis url from the arguments and trying to connect Redis. If connection fails then we immediately exit the program and put example usage command.

Let’s assume that we have connected to Redis. Now we can ask for the name. We will use blessed library for this purpose.

Image for post
Image for post

Now we have 2 clients for pub/sub and we get the name from the user. So Lets make another screen for ChatRoom and write simple logic for incoming/outgoing messages.

First draw the screen:

Image for post
Image for post

Now lets write a simple logic for incoming/outgoing messages.

That’s all. We wrote a simple chat application by creating only two node.js file. We drawed the screens and used the redis pub/sub for communication.

Conclusion

https://github.com/Lambda-Store/taalk

Lambda Store

Everything on serverless and cloud

Rafael Nunes

Written by

software architect @ https://lambda.store https://twitter.com/devnunes

Lambda Store

Lambda Store is the first Serverless Database for Redis. In this blog, Lambda Store engineering team shares their experiences on Cloud, AWS, Kubernetes, Redis and of course Lambda Store. https://lambda.store

Rafael Nunes

Written by

software architect @ https://lambda.store https://twitter.com/devnunes

Lambda Store

Lambda Store is the first Serverless Database for Redis. In this blog, Lambda Store engineering team shares their experiences on Cloud, AWS, Kubernetes, Redis and of course Lambda Store. https://lambda.store

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store