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
- A Serverless Redis Database. ( https://lambda.store )
- Basic Redis knowledge
Let’s take a quick look for our design:
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.
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.
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
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.
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:
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.
Please give a try our chat application and give us feedback. You can find the source code from here. Also please feel free to make any contribution or bug/fix.