Nest.js Crash Course #1 – Introduction & Setup

In this series you’ll learn how to make a ninja-themed API with Nest.js, which is a node.js framework for making server side applications.

⭐ Thanks to Marius for making this course. Subscribe to his channel here –

?‍? Nest.js docs –
?‍? VS Code –

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

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *