Nest.js Crash Course #1 - Introduction & Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right then gang so welcome to this series where you're going to learn all about nest.js which is a framework for building node.js applications now to teach all about this I'm going to hand you over to Marius who is an awesome content creator here on YouTube he's got loads of nest.js content on his channel as well as tutorials about a whole bunch of other things like react view graphql Etc so definitely definitely check out his channel And subscribe to it the link is going to be down below the video anyway without further Ado I'm going to pass you over to Mario so you can learn how to make an API with nest.js foreign [Music] doing a guest post for Sean here today I'd like to share with you the nashjs framework which I would argue is one of the best Frameworks for node.js especially if you're trying to build an API or other types of server-side applications it's got a great set of features awesome documentation and a massive Community behind it if you take a look at their GitHub page you'll see that they have over 50 000 stars there in this video series I'll introduce to you all the core fundamentals that you need for an sjs to get you started in building your own applications now before we get started let's quickly talk about why nest and what even is Nest as some of you may know a very popular framework in the node.js ecosystem is expressed it's been around for quite a long time now but by Design it's meant to be very minimalist it introduces to you a few Concepts that let you build apis however for the most part the overall architecture is up to you right if you take a look at their docs all they really have here is hey here's how you do some routing some basic middleware and error handling and then that's pretty much it this lack of architecture means that it's extremely flexible you can pretty much do whatever you want with Express however as your project or team grows you'll find that things can very easily turn into spaghetti you really need conventions and structure those are very important especially when you need to start integrating with things like graphql or rest or Swagger how do you do those things it kind of leaves it up to you to figure it out now where Nest comes into the picture is that basically they say hey let us take care of the architecture piece will give you the guidelines on how to architect your server-side application and the best part you still get to use express under the hood so you can kind of Imagine That natural yes kind of sits on top of express it simply introduces an out of the box architecture gives you a little bit of guidelines and the best part is that because it's sitting on top of it it means that all the things that the open source Community has built for express.js a lot of that is so ultimately usable in an SGS ecosystem if we briefly take a look at the necess documentation you can see that there's a couple of car Concepts here that we'll cover in this video series but above that you'll see that they have guidelines here on how to do a lot of extra things like how do you do testing and how do you do database connections and task scheduling cues and events websockets graphql there's a lot of things here and I should also mention messages is very big on typescript as you can see here combining lots of elements from op functional programming you'll see that there's a big emphasis on decorators which you might be familiar with from other Frameworks like spring and the Java ecosystem so that's next year's at a high level there's definitely a lot to learn and we're going to go ahead and create our own application so that you can learn those fundamentals we're going to build a net ninja API that uh you know think of it as an interface to manage your own Army of Ninjas so kind of random but also hopefully kind of fun all right so to get started open up a terminal hopefully you've got node and npm installed already I'm gonna go ahead and install the nest.js CLI the CLI is basically think of it as a way to help you generate new projects it also has a couple other extra commands that I'll show throughout the series to create a new application with the nest CLI you just have to use the nest new command like this and then provide your own project name I'm just going to call this one ninja API hit enter and it's going to ask you what package manager do you want to use I'll select npm here but feel free to use whatever you like and as you can see it's going to start creating a bunch of files for me and then it'll start installing my dependencies from here I'm going to go ahead and open the net ninja API and vs code all right so here's the new application we just generated I noticed that there's a couple files in here that we'll talk about in a sec but go ahead and open package.json which is where you'll see that there's a bunch of scripts in here commands that you can run in the terminal uh the different things you can do with this application so for example uh how do you start the application I will use this in a sec to start that which is starting the application in watch mode how to build how to format all your files using prettier testing Etc so let's go ahead and try that start Dev command in the terminal and it should output some stuff in here and it'll say Nest application successfully started now if we take a look in the main.ts file here which is think of it as the entry point for our application you can see that it's listening to Port 3000 you can change that though if you want so let's go ahead and make an HTTP request to that Port I'm going to do a new request here using thunderclient it's sort of like a postman that you can use right in vs code so I'm going to do localhost 3000 HTTP get and if I hit send here you'll see that we get hello world so let's take a quick look at the code that we have to see how is it set up to respond with this hello world message so back in the main.ts file you can see that the application is being made off of this app module in here and if we go into that that module has a couple things in it controllers and providers we'll dive deeper into what those things are in the following videos but let's just take a look with an app controller you can see that there's a method here that is probably getting invoked says get hello and that ultimately also invokes an app service that itself has its own get hello if we go into that you see that we have the app service returning the hello world message so if you kind of think about it the request on slash is basically just going to our controller and then that forwards to our service and then It ultimately bubbles back up in the other direction to give us our response of hello world so there's not much code here yet but you can already see sort of a high level architecture that in SGS is telling you to use for example controllers are defining the routes and then you know what HTTP verbs are we using for those routes represented by methods and then those methods ultimately call services which services will have you know your business logic and any sort of reusable logic that you want to use across you know whatever other services or other controllers that you have let's go ahead and maybe just change this to something else to prove that you know we can change the response so maybe let's do hit gang as Sean likes to say let's take a look at our thundercline again and let's make that same request hit send you should see that now it says our updated message now we didn't really go into detail about what modules controllers and services are in the following videos we're going to break down each of these topics and more we've got a full crash course for you here today and we're going to build again a net ninja API you're going to manage your own Army of Ninjas so make sure to head on over to the next video where we'll talk about uh what are modules and in general creating new resources for our API
Info
Channel: Net Ninja
Views: 80,278
Rating: undefined out of 5
Keywords: nest.js, nest js, nestjs, nest, nest js tutorial, nest.js tutorial, nestjs tutorial, tutorial, nest js vs express, node tutorial, node frameworks, what is nest js
Id: pcX97ZrTE6M
Channel Id: undefined
Length: 8min 5sec (485 seconds)
Published: Tue Feb 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.