I wrote a REST API with TypeScript… here’s the story.

Prince Igwenagha
5 min readJul 29, 2022
Sleeping cat.

It all started with the desire to try something new…

Being a Python back-end developer, I sometimes wanted to know what it felt like to build in another programming language, another language like JavaScript along with its environment-Node.js. People always talked about it everywhere, mostly on tech twitter. That’s how I felt the urge to experiment.

Before now, I have always hated JavaScript (may be I still do). No matter how hard I tried to learn it, it couldn’t stick. I guess this was because of its association with HTML and CSS. Yes, I once aspired to be a front-end developer before switching over to back-end development. There were hard times with CSS, and because of that, I hated it, and somehow, this hatred was transferred to JavaScript. I guess that’s why nothing refused to stick when learning it.

JavaScript was given another chance…

What exactly was Node.js? Was it another programming language, or another JavaScript framework? I asked myself these questions before, but I never really look for the answer. “Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine”. LOL, as if I knew what that meant. I read some articles on Node, and summarized it as “an environment that helps JavaScript be a back-end programming language” that’s all. After giving it so much thought, I decided to learn JavaScript again.

Brushing up with the basics, I didn’t really go too deep into it, because I wanted to create something out it. Once I felt I knew enough JavaScript to start something, I began to read about Node.js and Express.js. “Express.js”, another popular word that came from mouths of other developers around me, and I asked myself, “is it as simple as Django?”, “will I understand it once I start?”. I took a leap of faith into the framework… and I was lost. I didn’t know how to start anything.

I went through books, articles, YouTube videos, everyone was saying something different on how to build. There was not a single universal law on how to create an Express application. This was not like Django. Django was so straightforward, it had a solid foundation that helped development process so easy, and inbuilt libraries known as “batteries”. I later discovered it was confusing because that’s just how it is. There is no rule when working with Express because it is un-opinionated, meaning you are the one define your application structure, not the framework. I remember one issue I had with Express was adding the necessary middlewares to the app.js file. I didn’t know which ones were very important and those that weren’t. After so much struggle with the framework, I dropped it, and I felt wasted.

Back to the drawing board…

After my not so good experience with Express, I turned to the internet for help, in search of other web frameworks that I didn’t know of. There was Express, Koa, Meteor, Hapi, etc. Most of these frameworks were quite similar to Express, at least that’s what the articles said. I didn’t want another Express with a different name on it. I wanted something that I could flow with once the basis was understood.

While I was researching on frameworks, I had some in mind. Frameworks like Loopback, Adonis and Meteor. At least they didn’t appear un-opinionated like Express.

Then the cat called…

After carrying out so much research, I found the one framework for me, NestJs. I didn’t fully accept it from the beginning. I was skeptical. Again, I started reading blogs, Reddit posts, watching videos on it, its features and architectural design. This was it. It was what I have been looking for, mostly because it looked a lot like Django. Inbuilt libraries, models were called entities, views and services for business logic, urlpatterns became controllers.

There was just one problem though, it used TypeScript by default, I didn’t know the language. Once again, I started learning the basics of another programming language. This time around, learning this language was not as difficult as JavaScript, that’s because TypeScript is just JavaScript… but with types. Few weeks later, I decided it was time to build with Nest. I started searching for resources to learn from — books and articles specifically, because I learn more by reading. Did I see resources? Yes. Were they helpful? Not really. For books, I only saw two, of which one looked like the pdf version of Nest’s outdated documentation, the other provided a pretty good explanation of the framework, but when compared to Nest’s documentation, you’d see that some things were missing, and that’s how I decided to turn to YouTube for help.

After watching about 3 or 4 tutorials videos, just to grasp the basic stuff, I decided to build with the documentation (ahh, yesss). Nest’s documentation was exactly what I needed. Most of the details there were almost self-explanatory, and very little of it made me go back to YouTube for more info.

Bugs and Errors. Oh My God…

So I decided to build a REST API where users can put up cars for sale and buy these cars, just little basic stuff. At first, I thought it was a simple CRUD API I could build in 2 or 3 weeks, but I was wrong. The fact that I was building with another framework that was not Django was a problem, and one little funny mistake I found myself doing was commenting with “#” instead of “//”.

During this time, I was also reading on AWS. I wanted this project to be deployed on AWS, but I wasn’t sure of how I’d do that. So I would say my focus was kinda divided. Errors from missing resource items that I forgot I deleted 😅, to using a MongoDB database(I had to learn basic stuff on this too, I am so used to PostgreSQL), to sending emails with Nodemailer, to deploying on AWS ElasticBeanstalk, to some other errors I’ve probably forgotten. You know when they say Google is your friend, in this period, Google and StackOverflow became my best friends. I asked friends and strangers for answers, and got help from communities. This experience was not a really fun-filled one, but I’m happy I learnt new concepts and design, and new technologies. Plus that, I was even able to create a Docker image of the application. It actually felt like entire application was contained in a box, no wonder Docker calls them containers. And no, it’s not running on AWS at the moment, I took it down after some time, because of service cost, but at least I least a few lessons from the experience.

Learning never stops…

In summary, I would say I’m proud of what I achieved, and by continuing on the path I’ve chosen, there will be more experiences and challenges to take on. By the way, the learning never stops. Here’s the link to the github repo of the project, just in case you want to check it out. Please feel free to connect with me on Twitter or LinkedIn.

Till then, keep coding.

--

--