You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Automated testing is considered an essential part of any serious software development effort. It is provides integration with Jest and Supertest out-of-the-box, while remaining agnostic to testing tools.
762
762
763
+
## Day 18 - NestJs-into (hello world)
764
+
765
+
1. It is mainly used to create Rest API, a NodeJS framework, builds on ExpressJs.
766
+
2. Embraces TypeScript, dependency Injection and Modularity("AngularforBackend")
767
+
3. Can be used to build MVC apps or Rest or GraphQl Apis.
768
+
4. Enforces clean code and a clear project staructure by giving you a series of building blockes.
769
+
5. Makes building complex application easy.
770
+
771
+
772
+
6. Lets install NestJs first.
773
+
774
+
https://docs.nestjs.com/first-steps
775
+
a) Open ```NodeJs command``` promt.
776
+
Setting up a new project is quite simple with the Nest CLI. With npm installed. [It is similar to angular installation]
777
+
<br>
778
+
b) ```npm i -g @nestjs/cli```
779
+
780
+
c) Create new project using NEST
781
+
```nest new project-name```
782
+
e.g. nest new day18-NestIntro
783
+
784
+
it will ask for which package manager you want yo use for. I have chossen npm. Now it will install all th dependent packages.
- Node_module - consist all the package installed for application. - you can get details from package.json.
795
+
- Src - is the mail folder on which we will work its contains all the source files.
796
+
- Test - it is nothing but test setup for application. by default in jest.
797
+
- .gitignore file - is file used to ignore the git uploads.
798
+
- nest-cli.json file - It is nest configuration file.
799
+
- package.json - contain all the installed module definations.
800
+
- tsconfig.json - is type script configuratio files.
801
+
802
+
c) let see what we have in src.
803
+
804
+
- <b> main.ts <b/> - its entry point for application. nodejs not run typescript so code compile to javascript.
805
+
if you will se the code here it is follow like expressJS.
806
+
Creating the server and which will work on 3000 port.
807
+
```ruby
808
+
const app = await NestFactory.create(AppModule);
809
+
await app.listen(3000);
810
+
```
811
+
- <b>app.module.ts </b>
812
+
Nest is written the application in the moduler form like angular.
813
+
As in above its written NEST is embraces modularity. Nest is not taken all the files in your working folder. it will take only which has imported their. <br />
814
+
Imported part in NESTJs is controller and provide. As you need to list over here.
815
+
```ruby
816
+
controllers: [AppController], // bundle of controller
817
+
providers: [AppService], // bundle of services
818
+
```
819
+
820
+
> Controller : it is responsible to get the comming request and doing something and response it back.
821
+
> Provider : it will inject the certain functionlaity to controller. it like service of database to get the data from database.
822
+
823
+
here you can see the ``` @module``` as the decorator which is attched to the class.
824
+
825
+
826
+
- <b> app.controller.ts - </b>
827
+
It is app class as AppController which is decorated by @controller.
828
+
It is having method of getHello() decorated by @Get
829
+
in Appcontroller you will find the code like below.
0 commit comments