How I Built a Command-Line Chat Application: Project Reflections
Published: 2023-06-08 21:16:06

---
title: How I Built a Command-Line Chat Application: Project Reflections
series: How I Built a Command-Line Chat Application 
published: true
date: 2023-06-07 22:20:05 UTC
tags: 
canonical_url: https://hayatscodes.hashnode.dev/how-i-built-a-command-line-chat-application-project-reflections
---

<!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->

- [Challenges](#challenges)
- [Lessons Learned](#lessons-learned)
- [Contributions and Future Improvements](#contributions-and-future-improvements)
- [Project References](#project-references)
    + [Demo Video](#demo-video)
    + [NPM Registry Link](#npm-registry-link)
    + [GitHub Link](#github-link)
- [Conclusion](#conclusion)

<!-- TOC end -->


In this article, we will delve into the challenges I encountered while developing the command-line chat application, along with the lessons I learned throughout the process. From the initial stages of structuring the application to tackling authentication issues and creating a user-friendly chat interface, I faced numerous obstacles that tested my problem-solving skills and programming knowledge.

<a name="challenges"></a>
## Challenges

I faced several challenges from the idea stage to the deployment of the app. Below I list the major challenges I faced building the app:

- **App structure:** I started building the app with no structure in mind, as I wanted to build fast and organize it later. Eventually, I struggled to organize the app for modularity. But the experience of structuring other backend projects and some little research on the MVC design pattern came in handy. I still think the app isn't well structured, though.

- **Authentication:** This was one of the hardest features I had to implement. With vague documentation and few resources to explore the `socket.io` library authentication, I had to spend several hours making the authentication feature work as expected. I initially wanted to store the token on the user's machine but found it to be buggy. So I changed my mind and used `HTTP` requests to store and retrieve the token from the server.

- **The chat interface's home menu feature:** I wanted the user to be able to go back to the home menu from the chat interface. I thought of using the `inquirer.js` prompts that were being used throughout the application. That was impossible because the `readline` interface continues to be displayed until it is closed. So I figured out that I could respond to the user's input to go back to the home menu. After that, re-rendering the home menu was also difficult. However, its implementation made the chat message interface code messy, and it also disobeyed the `DRY` principle.

- **Railway Redis:** I've used Redis in development before but never in production. This project was my first time setting up Redis in production. Since I was deploying on Railway, it was supposed to be easier. But it took time for me to understand how to set up a Redis database, as their documentation wasn't really clear.

- **Publishing to NPM** : Publishing my first NPM package was challenging. With little time before the project submission deadline, I learned how to publish on NPM and named the app `terminal-chat-app`. However, after installing the app from the NPM registry for manual testing, I realized I forgot to add the node shebang line to the app's node script. After correcting the issue, I encountered a version error while attempting to republish. Not knowing what to do, I deleted the package and got another error that I had to wait 24 hours to publish again. To meet the hackathon deadline, I temporarily changed the package name to `tarminal-chat-app`. However, I couldn't change the package name again because it now has more than 130 weekly downloads on NPM.

<a name="lessons-learned"></a>
## Lessons Learned

- **It's usually unclear at the beginning:** I barely knew command-line and web socket programming before the project, and I was still able to make something out of those unfamiliar tools.

- **It takes time to build great stuff:** I planned to finish the app in a few days, but it took me 2 weeks of debugging, problem-solving, and building to finish the app. Although, if I had known all or most of the technologies used, I would have finished earlier. But I realized that it's not the normal CRUD API that I'm used to building, so it took more time than expected.

- **The definition of a minimum viable product (MVP):** A lot of features came to mind while building the app, but I had to settle for the easiest feature to implement and think of building upon that later. So if the app was a business product, I'd say what I built was the MVP.

- **Programming Fundamentals help a lot:** Knowing some programming fundamentals makes things easier. From recursively calling functions to separating code for modularity, it helped make the project a success.

- **Build first, refactor later:** I started building the app without having any code best practices in mind. It made building faster as I focused on solving the problem at hand rather than writing clean code. I only started refactoring after the app was ready and in good condition.

<a name="contributions-and-future-improvements"></a>
## Contributions and Future Improvements

The project is open source, and everyone is free to contribute to it. Some of the improvements that can be made are:

- Restructuring the app files for more modularity

- Adding a private chat messaging feature

- Adding a group messaging feature by asking for a code before joining

- Better error handling

- Tests for the client's code

- Real-time notifications

- Restore 10 or more of the previous messages

- and more...

<a name="project-references"></a>
## Project References

<a name="demo-video"></a>
#### Demo Video

[https://youtu.be/q7R8VUhbzQs](https://youtu.be/q7R8VUhbzQs)

<a name="npm-registry-link"></a>
#### NPM Registry Link

[https://www.npmjs.com/package/tarminal-chat-app](https://www.npmjs.com/package/tarminal-chat-app)

<a name="github-link"></a>
#### GitHub Link

[https://github.com/HayatsCodes/terminal-chat-app](https://github.com/HayatsCodes/terminal-chat-app)

<a name="conclusion"></a>
## Conclusion

It was fun and challenging to build yet another project. From learning new and unfamiliar technologies to implementing several features, it was an enlightening and enriching experience. I look forward to building more and more as I search for my first job.