No video
Fastest Way to Create APIs? | NestJS Tutorial
In this video I walk you through one of the fastest ways to create a fully working RESTful Node.js CRUD API utilizing the Nestjs framework, TypeORM, Swagger/OpenAPI, and a few other packages!
00:00 - Intro
00:15 - What we'll be building
04:28 - Nestjs installation
05:52 - Generated initial code overview
06:44 - Generating Users Module
08:44 - Adding Swagger
11:26 - TypeORM / Database sqlite config
13:31 - Create User entity
16:10 - CRUD Generator?
17:00 - nestjsx/crud
18:16 - Users Controller
20:07 - Users Service
23:20 - Implementation Complete! Demo
25:45 - Conclusion
26:06 - How to customize further
26:53 - Outro
Пікірлер: 118
I spend quite a bit of time explaining things through this video however you'll notice that the total amount of code written is not a lot at all. This means that once you know how to do this, it will probably only take you 10-15 minutes to do! If you want jump ahead to the implementation you can go to 17:00 or use the other timestamps below. If you have any feedback let me know! 00:00 - Intro 00:15 - What we'll be building 04:28 - Nestjs installation 05:52 - Generated initial code overview 06:44 - Generating Users Module 08:44 - Adding Swagger 11:26 - TypeORM / Database sqlite config 13:31 - Create User entity 16:10 - CRUD Generator? 17:00 - nestjsx/crud 18:16 - Users Controller 20:07 - Users Service 23:20 - Implementation Complete! Demo 25:45 - Conclusion 26:06 - How to customize further 26:53 - Outro
Aint I glad I bumped into your video. You are the first person to teach me Nestjs in a way I actually understood. Thank you so much
@mariusespejo
3 жыл бұрын
Glad I could help!
Loved this framework CRUD. I was doing something similar as a side project 2 years back and just realized it's already there in market. Thanks for the video.
Great piece of work, mate! This certainly going to inspire me to learn more about NestJS. Quite a powerful and helpful framework for an experienced node API developer!
@mariusespejo
3 жыл бұрын
thanks glad to hear! If you’re already doing some node work I definitely highly recommend giving Nest a shot!
It really nice that nestjs already have CRUD and plus a auto generated documentation by Swagger!!! I used to create custom file in express. Thanks for this!
@mariusespejo
3 жыл бұрын
same, I had to go through the pain of writing specs manually with express haha never again
Thanks for this intro, very helpful.
@mariusespejo
3 жыл бұрын
thanks for the feedback! glad it’s helpful
This tutorial is great! Thank u so much!
Thank you so much for your wonderful work. It is very helpful. I enjoy watching your video and really like the way you explain things - simple, clear and relaxed.
@mariusespejo
2 жыл бұрын
Thanks for stopping by to comment 🙂
Great video brother.
@mariusespejo
2 жыл бұрын
Thanks Rick! 👊
Great tutorial! Thanks for sharing it!
@mariusespejo
Жыл бұрын
Glad it was helpful!
Thank you for this amazing tutorial! SUBED!
Damn 🔥 Quality content. Keep it up man
@mariusespejo
3 жыл бұрын
hey Mark! thank you!
Thank you for your great work! Your videos are really useful.
@mariusespejo
2 жыл бұрын
Thank you!
very helpful!
Thank you for saving me some hours of work man
@mariusespejo
3 жыл бұрын
no problem! glad it’s helpful
I am the 250 subscriber!
@mariusespejo
3 жыл бұрын
haha yes!!
hello I can't run users module and controller, maybe anyone can help me?
Really cool bro!
Hey bro, I'm getting error on the typeorm installation, do you know if this is a conflict with the M1 macs or something like that? I just cant do that, sadly
@smren
2 жыл бұрын
nvm, I just tried using mysql2 and it worked for some reason ._.
@mariusespejo
2 жыл бұрын
@@smren glad you got it working! There is also an incompatibility at the moment between @nest/typeorm, typeorm 0.3.x, they're still working to support that new release. So I'd use typeorm 0.2.x for now
my hero of the day real boss
Thank you so much, this is very useful
🔥🔥🔥 Man You are underRated 😫😫 You saved me so much time...❤❤ I'll share your vidéo to all of my communities cause you deserve it !🙌🏿🙌🏿 💨 Thinking about it 🤔: Did you think about creating a Discord Server for your youtube community ?
@mariusespejo
3 жыл бұрын
I don’t think I have enough subscribers to build a community hahaha I do plan to make content consistently so maybe if one day it grows quite a bit more. Anyways I appreciate you sharing the video!
@OrbitTurner
3 жыл бұрын
@@mariusespejo Okay 😂 I will be waiting For That Man Hope it will be sooon 👍👍
Thanks, really helpful. Also could you do one with Microservices?
Hey! can you tell how you add that cool effect in terminal, I am talking about fade particles effect, Thank you. You are one of the best instructor.
@mariusespejo
Жыл бұрын
I was using the hyper terminal here, it’s just one of the default plugins you can install
@shabbirhusain6634
Жыл бұрын
@@mariusespejo Thank you mate. Love the way you taught😃
Thanks for the amazing tutorial. Do you plan to make more content? If so, then can you please please create a series or big video on CRUD Operations and User Authentication using MEAN Stack but with NestJS instead of Express. Angular, Mongo, Nest and Nodejs, CRUD's with user authentication. Thanks again for the amazing video.
@mariusespejo
3 жыл бұрын
definitely making more fullstack content! thanks for the suggestion!
@theoverallsite
3 жыл бұрын
@@mariusespejo Thanks and ur most welcome, looking forward to it.
@martinmtandi335
3 жыл бұрын
they is too much content on Mongo, do one with TypeORM like you did here but like a proper API with authentication and stuff
@mariusespejo
3 жыл бұрын
definitely!
@mariusespejo
3 жыл бұрын
just added a deeper dive on TypeORM if you're interested! kzread.info/dash/bejne/pYKj1a5uZ5urc9I.html
what is the microphone you are using? name please? Also how do you capture yourself? And many thanks for this nice little tutorial
@mariusespejo
3 жыл бұрын
if you’re interested in doing similar recordings I would suggest starting with a usb mic like the blue yeti, which I use in my older videos. There are various ways you can record the screen as well as yourself, on Macs there is quicktime (free) and screenflow for example. On windows there is the game bar that can also record, and camtasia I believe is a popular paid one. Lots of different options. Hope that helps!
Thank you Marius for great Video, maybe you can tell the best way to group Response data with nestjsx/crud ?
You didnt say about load balancing. At this time, I have nest js app like this and when many clients requests api, a lot database queries awaits created. It stacks node js and server stops responding.
@mariusespejo
2 жыл бұрын
That doesn’t sound like a load balancing problem, do you have multiple instances of your server? Anyways there are other solutions for load balancing, it’s outside the scope of this video
nestjsx/crud has been without any update for years. It doesn't even work fine with typerom > 0.3. Any alternatives?
@mariusespejo
7 ай бұрын
Good to know thanks! I’m not aware of anything similar, but honestly you can just use the nest cli to auto generate all the CRUD boilerplate for you, you’d just need to add the db queries
@Imsurethishasnotbeentaken
7 ай бұрын
@@mariusespejo well, that package did that automatically and also provided a client to interact with it (with filtering and pagination)
@mariusespejo
7 ай бұрын
Yes, so if you’re heavily invested in using it your best bet is to not upgrade typeorm (or downgrade). Personally I think whatever is auto generated for you is not a ton of work to do yourself. It does save you some boilerplate, but in the long run I’ve found it to just get in the way once you need more customization. If having a client is the most important aspect, personally I’d rather use ts-rest and create a type-safe client which is auto generated from a contract that your API adheres to (I made a video about that if you’re interested)
@Imsurethishasnotbeentaken
7 ай бұрын
@@mariusespejo thanks for the replies. I’m not really interested in ts-rest. I mean, if I typed everything in the entities and dtos , I just prefer to consume the swagger and autogenerate from that. The APIs I develop are for my apps and also for the clients that use my apps, so they can’t integrate however they want with their current apps. There’s a fork from crudx but it’s not as maintained as the original one. Right know in playing with api platform (which is built on top of Symfony), which right know I think is the fastest way to have a rest api up and running
This import completion is problematic, it's difficult to instatiate. Which extensions are you using for this?
@mariusespejo
5 ай бұрын
Import intellisense is generally just typescript, it doesn’t require extensions
Am I the only one having this issue? ts-loader 9.4.2 missing peer webpack@^5.0.0. Do I need this ts-loader if so should I install the webpack?
@mariusespejo
Жыл бұрын
Did you use the Nest CLI to create your project? It should have come with webpack and installed it for you
@theBarracuda_
Жыл бұрын
@@mariusespejo yup. Maybe that’s could be related to pnpm?
@theBarracuda_
Жыл бұрын
@@mariusespejo also, wanted to say that you’re doing an incredible work, keep going !!
@mariusespejo
Жыл бұрын
Thanks! Anyways Nest does use webpack when you run it in dev/watch mode so something is not right with your dependencies installation
@theBarracuda_
Жыл бұрын
@@mariusespejo lol weird I was able to run start:dev and everything was just fine
Nice content. Thanks
Do you have a tutorial on creating seed data for NestJS? I am trying to find a way to do it, that it is not specifically tied to TypeOrm.
@mariusespejo
3 жыл бұрын
I do have a video on typeorm which covers migrations which can also be used to seed data. Other ORMs have an actual seeding feature
All of the filtering, search, sort, etc... did you have to manually set any of that up?
@mariusespejo
2 жыл бұрын
No, did you watch the entire video? Pretty I sure I show exactly what minimal setup I had to do
Thank for the content.... Your NestJS videos are really helping me. I am curious to know how you are getting that NPM Scripts tag at the left bottom using which you are running npm scripts.
@mariusespejo
3 жыл бұрын
thanks! That npm window is built-in to VS code im pretty sure. Maybe add this to your settings if you’re not seeing it: “npm.enableScriptExplorer”: true
@aravindpvk
3 жыл бұрын
@@mariusespejo Figured it out in the meanwhile. Thank you again.
Would you recommend using it as a SPA with any React Vue or Angular or use it with a template thanks.
@mariusespejo
3 жыл бұрын
Nest uses Express under the hood by default, so technically anything you can do with Express you can do with Nest. That includes template rendering with handlebars, pug, etc. And yes you can have it “serve” up SPAs with react/angular/vue. However it’s core purpose as a framework revolves more around developing microservices. If you just need a basic static file server, probably better to use Express or others.
Thanks for the video. Can we use the nest/crud package for Mongo? or do you know any alternative package for the Mongo. Thanks, heaps.
@mariusespejo
3 жыл бұрын
At the moment, it doesn't seem like it. Sounded like they had intentions to do it, but never made the implementation. See: github.com/nestjsx/crud/issues/152
@KavehSaket
3 жыл бұрын
@@mariusespejo I see. Thank you.
I use the command "yarn add --save @nestjs/sequelize" but when importing { SequelizeModule } from '@nestjs/sequelize'; error Cannot find module '@nestjs/sequelize' or its corresponding type declarations. I use "yarn add --save @nestjs/sequelize" again and it gives me the error "error Missing list of packages to add to your project."
@mariusespejo
2 жыл бұрын
I don’t think I used sequelize for this video? Might be better to ask this on in stackoverflow
no metadata for user found
This video was awesome! Can you please tell me what theme you use in vscode?
@mariusespejo
3 жыл бұрын
thank you! In this video I believe I was using night owl because the contrast looks good for recordings, but typically I would use One Monokai
its strange I followed everything step by step and on the swagger I get 500 response
@mariusespejo
Жыл бұрын
Always check most recent docs, things change quickly
@bombrman1994
Жыл бұрын
@@mariusespejo alright, thanks will give it a shot following the docs this time.
Thanks
When you are typing in your terminal, you get a cool effect. How do you did that? :D
@mariusespejo
3 жыл бұрын
people ask that often! haha I'm using hyper as my terminal for that, the effect is just one of the plugins. Take a look: hyper.is/
@productive1185
3 жыл бұрын
@@mariusespejo Thank you very much for the quick answer! :D
what's the theme you are using?
@mariusespejo
2 жыл бұрын
I believe night owl in this one
is there any Part 2 or something or is this "done"?
@mariusespejo
3 жыл бұрын
It’s not a series, just an intro to the package. Was there something specific you were looking for? The docs for that package are quite good
@blacktipe9922
3 жыл бұрын
@@mariusespejo well some web scraping api like cat api that will generate random pics would be insne
@mariusespejo
3 жыл бұрын
Practically speaking I would just use something like the unsplash api for that lol I don’t know much about web scraping tbh, maybe I’ll give it a try sometime. You should go for it though, if you’re looking for a side project
Nest JS transaction, maybe it's the good topic.
@mariusespejo
3 жыл бұрын
will consider it, thanks!
could you please share the source code link
@mariusespejo
3 жыл бұрын
sorry I didn’t push this to a repo. If you need a written reference I highly recommend using the official nest docs as well as the crud package docs, they’re both extremely well documented
what is really a service ?
@mariusespejo
3 жыл бұрын
hey Nathaniel, I have another Nest Crash Course video on my channel which goes over the fundamentals. I would maybe recommend taking a look at the first, goes into much more detail
@NathanielBabalola
3 жыл бұрын
@@mariusespejo okay, thanks. Please can you post the link
@mariusespejo
3 жыл бұрын
kzread.info/dash/bejne/ZKJn2rVxabewfaw.html
@NathanielBabalola
3 жыл бұрын
@@mariusespejo thank you
bye bye php and express hehe
@mariusespejo
3 жыл бұрын
Well still express under the hood by default 😅
@lutfiikbalmajid3128
3 жыл бұрын
@@mariusespejo haha yes, i just read the author, its based on express and socket io thats why could be realtime. cool
@lutfiikbalmajid3128
3 жыл бұрын
@@mariusespejo btw thanks for your tutorial. like it!
Thank you for great tutorial material, maybe someone has problem with POST method within @PrimaryGeneratedColumn() ? this always return NULL, not generated number
@mariusespejo
3 жыл бұрын
likely a problem with your datebase config, perhaps you never ran migrations?
@matrixantas
3 жыл бұрын
@@mariusespejo Yes you are absolutely right, no migrations. Is it possible to make it work without migration with existing schema and data ?
@mariusespejo
3 жыл бұрын
yes as long as your existing schema in the db matches what you’re representing in the entity. For example it sounds to me like your primary key is not already an auto incrementing int, which is what @PrimaryGeneratedColumn does. You’d have to update the your database to match, and the proper way to do that is through a migration