Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right, On to steps number three and four.
So in step three, we need to create a Nest module and a controller.
I want to very quickly tell you what a module and a controller are.
So we're going to take a look at a couple of different diagrams.
All right.
So this diagram right here is probably going to look somewhat familiar if you've ever, ever put together
any kind of server.
So in just about every Http server you're ever going to create, you're going to have what is referred
to as a request response cycle.
Users are going to make requests to your server inside of your server.
You're going to have some amount of code that's going to process that request.
You might validate some data inside the request.
You might handle the request differently depending upon what route it is addressed to.
And then eventually you're going to formulate a response and send it back to whoever made the request.
Now, just about every server you ever put together, this code right here that's going to process that
request is almost always going to look rather similar in nature.
In other words, this kind of request response cycle almost always has the same steps inside of it,
regardless of the language framework library or whatever else that you use to build your server.
So this code or that process almost always looks something like this.
So just about every server that you're ever going to put together is going to receive a request.
It then might do some validation on data contained inside that request.
So for example, we might validate some body or some data in the body of the request.
We then might make sure that the user is authenticated or authorized to send us a request.
We're then going to route the request off to a particular function to handle the request that might
result in us running some particular business logic and eventually maybe access or store some information
inside of a database.
Then as a result of this entire process, we're going to formulate a response and send the response
back to whoever made us the request.
So, again, doesn't really matter what language framework, anything that you're using, just about
every server is going to have the same series of steps.
In some cases we might not be doing authentication, so maybe some steps will fall out.
But at the end of the day, this is kind of a very general case.
So in Nestjs we get special tools to help us address each of these very particular steps.
So in Nest we have tools to help us create something called, say, a pipe.
Pipes and nest help us validate data on incoming request.
We also have tools that allow us to create something called guards.
Guards make sure that incoming requests are coming from users who are authenticated or authorized to
use our application.
We get also tools to create controllers.
Controllers contain routing logic.
We get tools to create something called services.
Those contain business logic and so on.
So throughout this course, as we work with Nest, we're going to learn about each of these different
sets of tools.
Each of these different sets of tools included in Nest are meant to help us kind of put together some
piece of handling an incoming request besides just the five I'm showing right here, there's a couple
of other tools we're going to look at.
So these are all tools inside of Nest that help us make things that handle these incoming requests.
So we still have controllers and services which we saw in the last diagram.
We also have something called modules.
We have pipes, filters, guards, interceptors and repositories.
And again, we're going to learn about all these things throughout this course.
Now, the absolute bare minimum that is required to put together the most simple application possible
is a module and a controller.
Every application you ever create is going to have at least one module and one controller inside of
it.
So in the diagram we were just looking at a moment ago, this one right here where we said we were going
to create a Nest module and a controller.
These are the two things that are required to make the most simple, basic app possible.
So with that in mind, let's go back over to our editor and we're going to create a module and a controller.
So back over here to get started, I'm going to create a new directory called SRC.
Then inside there, I'm going to make a new file called Main.ts.
Main.ts is going to be the first file that gets executed in any project.
So we'll usually have some code inside of here to start up our application and start listening for traffic
on a particular port.
Usually we will create a module and a controller in their own separate files.
But for right now we're going to create the module and the controller directly inside the main.ts file.
So for right now, all logic inside this file.
But we will very, very quickly extract the stuff into separate files.
To create a module in a controller.
We're going to add in an import statement at the very top, and I'm going to import something called
controller and module from at Nestjs slash Common.
So like I mentioned, these are tools that Nest provides to us to help us make a controller and make
a module.
To use them to create a controller.
We're going to focus on the controller first.
I'm going to create a class called App Controller.
And then right above it, I'm going to add an at symbol controller and then call that like a function.
So this is referred to as a decorator In this case, this decorator is telling Nest that we are trying
to create a class that is going to serve as a controller inside of our application.
It is a class that is going to handle and route incoming requests.
Nest makes use of decorators quite heavily.
So throughout this course, we're going to have a big focus on decorators, how they work and so on.
But for right now, we're just going to add these decorators in and we'll discuss what they're really
doing for us later on.
Then inside of our class, we're going to add in a variety of different methods.
Each method is designed to handle one kind of incoming request.
Specifically, we want to add in an additional method anytime we want to have another route inside of
our application.
So, for example, if we want to handle a get request to the root route of our application, we might
add in a new method here called something like.
Get root.
Root.
Then whenever someone makes a request to our application, we want to route that request to this method
right here.
To do so, we're going to import another helper from the Common library.
This helper is called the Jit decorator.
This allows us to create route handlers that respond to incoming requests that have an Http method of
Jit.
So right above my method, I'm going to put in at Jit like so.
Then inside my method, anytime someone makes a request to our root route, that's going to run this
method right here, and then all we have to do to respond to that request is return a value from this
method.
So in this case, I'm going to return simply a string of Hi there.
Now, in theory, if someone makes a request to our application, it will get routed to this method
right here.
We're going to return that string, and nest is going to automatically take that string and send it
back to whoever made the request.
All right.
So a lot of talking here, a lot of stuff going on.
Let's take a pause very, very quickly.
Come back in just a moment and start to create our module.
Last thing I want to mention is if these decorators and things are really confusing right now, don't
sweat it.
As I mentioned, we're going to be going over decorators a tremendous amount inside this course.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.