Let's create a CRUD Rest API in Typescript, using:
NestJS (NodeJS framework)
TypeORM (ORM: Object Relational Mapper)
Postgres (relational databas...
For further actions, you may consider blocking this person and/or reporting abuse
Some crucial points are missing, like DTOs to validate incoming requests and transform responses.
And the general approach is far from a perfect one.
If you're a novice, then this article might be helpful, yet it doesn't follow best practices.
For instance, you shouldn't have any business logic inside controllers: you should get a user and check if it exists inside a service.
Next, better to have a data service to work with database. A service shouldn't know anything about database and ORM you use. All those things should be in a data service
Agree
However, for newbies this article should be okay
that's the point of the article
yes this is not intended to be a production ready code. thanks for the feedback
This article is awesome for newbies who just want to bootstrap an app real fast. Thank you for sharing your thoughts too.
What about adapting nestia?
With it, you can use pure TypeScript interface type as DTO, and also can generate advanced SDK (something like tRPC) and swagger than ever.
the goal of this artricle is to focus on the basics for beginners
Nice article, thanks for your help. May I ask if you've considered using MikroORM instead of TypeORM. I have used both and found MikroORM to work a lot better, but I am interested in your opinion.
I haven't heard about MikroORM, yet personally I prefer Prisma. You needn't create classes for your tables. It generates classes/types automatically. It's interesting that all auto generated stuff is located in node_modules, so that your sources don't have them. I strongly recommend to try it out
never heard fo that
It is a typescript ORM, like TypeORM, but with far fewer issues, more active development, better support and overall just better in my opinion. However, I think with the current state of typescript orm's you should also have a look at Prisma. In general I believe that TypeORM should not be used anymore.
why don't use TypeORM? Please help me clarify this
In my experience MikroORM has far fewer bugs. The support by the maintainer is very good, the maintainer is active in development, responds quickly to problems. Actually just the same reasons as I already stated.
I'm a DevOps trying to understand and make life easy by creating some API. This tutorial helps me create a single API and understand the code for the container deployment in a local env.
Thanks for the guide.
you are welcome
I found your article very helpful. Can you make a real world example using nestjs + postgres + typeorm? I really need to dive deep into the ioc mechanism of nestjs. Really good article! Congratulates!
Thank you. here are the examples
Manage products, categories, orders, and inventory in an e-commerce platform.
User management and blog post CRUD operations in a blogging platform.
User profiles, friends/followers system, and messaging in a social media app.
Task and project management with real-time notifications in a task management tool.
Francesco, I found this article very helpful and well structured. Thank you.
thank you Francisco
thank you Francisco, very detailed explaination and code. thanks a lot.
you are welcome Shoban.