DEV Community

Creating your first Node.js REST API with Nest and Typescript

Chris Noring on June 17, 2019

Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris A progressive Node.js framework for building efficient, rel...
Collapse
 
kyriakosmichael profile image
Kyriakos Michael

I always had fear of starting with a Typescript First Framework. I gave Nestjs a try, and I'm really happy with the Developer Experience!

Build this API in less than 10 minutes, and I notice .spec.js File are being generated too!
This is a great approach to helping developers writing Test-Driven backends!

Nestjs got my attention!

Collapse
 
softchris profile image
Chris Noring

Yea I have the same experience with Nest, it just works :)

Collapse
 
dmitryvdovichencko profile image
Dmitry Vdovichenko 💻🤘 • Edited

Thanks for the great article) I always start to learn new things in a simple CRUD way. For me, it's something confusing because I used to work with Express and React in my projects) And I'm not familiar with Angular. But it seems like a more clean and well-tested backend architecture)

P.S. When I go through this nice tutorial with CRUD methods, I've decided to move the filter function, which used for getting a product by id, to ProductService ))

Collapse
 
zmotivat0r profile image
Michael Yali

Great article!
Btw, I've created this lib to help with some CRUD scaffolding github.com/nestjsx/crud
Hope that will help people too 😺

Collapse
 
softchris profile image
Chris Noring

thanks Michael. You should try pinging @kammysliwiec or @markpieszak on twitter. I'm sure they would love to hear of a lib making people more efficient :) I'll have a look too of course

Collapse
 
zmotivat0r profile image
Michael Yali

Yeah, Kamil knows about that lib for sure :) I know he prefers mixins but I made it more powerful and feature rich. He said that he already suggested that lib during one of his workshops, hehe :)
Thanks again for this article. You should definitely add it to this awesome list github.com/juliandavidmr/awesome-n...

Collapse
 
bergermarko profile image
Marko Berger

Definitely, need to try it. Almost Angular backend;

Collapse
 
softchris profile image
Chris Noring

100% agree. Also there are so many lovely bindings to things like GrahpQL, Swagger, ORMs.. :)

Collapse
 
727021 profile image
Andrew Schimelpfening

Great article! I’m really looking forward to trying Nest.

Collapse
 
robosek2 profile image
Robert Sęk

Great introduction to NestJS! Thanks for this post :-)

Collapse
 
colmben profile image
colmben

Great article, a really concise intro to Nest. A couple of small points:

  • In the controller @Get, you are returning an array (from Filter). When you Type this up against your interface that is going to look strange. I'd be more inclined to just use .find to return the first one found.

  • For Delete, deleting against the Body object feels weird. I know you are not explicitly creating a RESTful API but if I can GET from products/:id, I would expect to DELETE the same way. So I'd expect to see @Delete(':id') in the service and that id used to find the object to delete.

Collapse
 
chechavalerii profile image
Valerii Checha
Collapse
 
jcarlosweb profile image
Carlos Campos • Edited

In my case i prefer github.com/TypedProject/ts-express..., in which it is not necessary to create modules and has a more flexible configuration

Collapse
 
maria_michou profile image
Maria Michou

Great article Chris, thanks for sharing!

Collapse
 
softchris profile image
Chris Noring

hi Maria, thank you for that :)

Collapse
 
frodk profile image
FroDK

What did you use for such a beautiful json rendering on the page?

Collapse
 
softchris profile image
Chris Noring

so that's just three back ticks+ json and then ending it with three backticks,

{}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
softchris profile image
Chris Noring

or in the case above, it's just Chrome json rendering in a browser, it's an image above

Thread Thread
 
frodk profile image
FroDK

it in Network > Preview response?

Collapse
 
bidipeppercrap profile image
Fransisco Wijaya

Why did you use interface instead of class on DTO?

Collapse
 
softchris profile image
Chris Noring

Hi Fransisco. I tend to use interfaces when all I need is shape, i.e something containing a few properties that belong together. If I can't motivate that I will instantiate it at some point an interface is a good way to start. If a find, later on, I need to create an instance of it then I will switch it to a class

Collapse
 
dansimiyu profile image
dan-simiyu • Edited

Great article. Really enjoyed it. Thanks man.

Collapse
 
softchris profile image
Chris Noring

appreciate that, thank you Dan.

Collapse
 
softchris profile image
Chris Noring

hi Vishnupriya. Are you suggesting that I post on the above blogs for better reach or ?

Collapse
 
tnypxl profile image
tnypxl

This was great. Getting me interested in Typescript too!

Collapse
 
softchris profile image
Chris Noring

Yea IMO it's easier to appreciate TypeScript when it's already set up. Although I do have TypeScript set up here if you are interested in that bit github.com/softchris/typescript-pl...

Collapse
 
kasanielaski profile image
kasanielaski

Great article. In last pic you used map + filter inside updateProduct method. Whould it be better to combine these and use only one reduce call

Collapse
 
softchris profile image
Chris Noring

please show me what you have in mind

Collapse
 
baldassari profile image
Asaph Baldassari

Festify or restify?

Collapse
 
softchris profile image
Chris Noring