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)
763
+
## Day 18 - NestJs-intro (hello world)
764
764
765
765
1. It is mainly used to create Rest API, a NodeJS framework, builds on ExpressJs.
766
766
2. Embraces TypeScript, dependency Injection and Modularity("AngularforBackend")
@@ -769,19 +769,19 @@ It uses package @nestjs/microservices.
769
769
5. Makes building complex application easy.
770
770
771
771
772
-
6. Lets install NestJs first.
772
+
6. Lets install NestJs first. <br />
773
+
https://docs.nestjs.com/first-steps <br />
773
774
774
-
https://docs.nestjs.com/first-steps
775
-
a) Open ```NodeJs command``` promt.
775
+
a) Open ```NodeJs command``` promt. <br />
776
776
Setting up a new project is quite simple with the Nest CLI. With npm installed. [It is similar to angular installation]
777
-
<br>
777
+
<br />
778
778
b) ```npm i -g @nestjs/cli```
779
779
780
-
c) Create new project using NEST
781
-
```nest new project-name```
782
-
e.g. nest new day18-NestIntro
780
+
c) Create new project using NEST <br />
781
+
```nest new project-name``` <br />
782
+
e.g. nest new day18-NestIntro <br />
783
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.
784
+
Tt will ask for which package manager you want yo use for. I have chossen npm. Now it will install all th dependent packages. <br />
- 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.
794
+
-<u> Node_module </u> - consist all the package installed for application. - you can get details from package.json.
795
+
- <u>Src </u> - is the mail folder on which we will work its contains all the source files.
796
+
- <u>Test </u> - it is nothing but test setup for application. by default in jest.
797
+
- <u>.gitignore file</u> - is file used to ignore the git uploads.
798
+
- <u> nest-cli.json </u> file - It is nest configuration file.
799
+
- <u> package.json </u> - contain all the installed module definations.
800
+
- <u> tsconfig.json </u>- is type script configuratio files.
801
801
802
802
c) let see what we have in src.
803
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.
804
+
- <b> main.ts </b> - its entry point for application. nodejs not run typescript so code compile to javascript. <br />
805
+
if you will se the code here it is follow like expressJS. <br />
806
806
Creating the server and which will work on 3000 port.
807
807
```ruby
808
808
const app = await NestFactory.create(AppModule);
809
809
await app.listen(3000);
810
810
```
811
811
- <b>app.module.ts </b>
812
-
Nest is written the application in the moduler form like angular.
812
+
Nest is written the application in the moduler form like angular.<br />
813
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.
814
+
Imported part in NESTJs is controller and provide. As you need to list over here.<br />
815
815
```ruby
816
816
controllers: [AppController], // bundle of controller
817
817
providers: [AppService], // bundle of services
818
818
```
819
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.
820
+
> Controller : it is responsible to get the comming request and doing something and response it back.<br />
821
+
> Provider : it will inject the certain functionlaity to controller. it like service of database to get the data from database. <br />
822
822
823
823
here you can see the ``` @module``` as the decorator which is attched to the class.
824
824
825
825
826
826
- <b> app.controller.ts - </b>
827
-
It is app class as AppController which is decorated by @controller.
827
+
It is app class as AppController which is decorated by @controller. <br />
828
828
It is having method of getHello() decorated by @Get
829
829
in Appcontroller you will find the code like below.
830
830
831
831
```ruby
832
832
@Controller()
833
833
export class AppController {
834
834
```
835
-
Means it will accept the empty parameter like
835
+
Means it will accept the empty parameter like<br />
836
836
your-domain.com/
837
837
838
838
if you have the parameter in controller like user
839
839
```ruby
840
840
@Controller('user')
841
841
export class AppController {
842
842
```
843
-
you need to use it like your-domain.com/user
843
+
you need to use it like your-domain.com/user<br />
844
844
845
845
Same happan for the get also if it is like
846
846
```ruby
@@ -865,31 +865,31 @@ this service should be registerd in the module. here you are declaring ut and us
865
865
this.appService.getHello();
866
866
```
867
867
868
-
-<b> app.service.ts </b>
868
+
-<b> app.service.ts </b> <br />
869
869
870
-
All your login aout the application or DB call are written to the service.
871
-
It is using @Injectable decorator code for AppService class. And defined a method like getHello in service.
870
+
All your login aout the application or DB call are written to the service.<br />
871
+
It is using @Injectable decorator code for AppService class. And defined a method like getHello in service.<br />
872
872
```ruby
873
873
getHello(): string {
874
874
return 'Hello World!';
875
875
}
876
876
```
877
-
Here you can write your complex logic.
877
+
Here you can write your complex logic.<br />
878
878
879
879
- <b>app.controller.spec.ts </b>
880
-
It used to write the unit test methods for app.controller
880
+
It used to write the unit test methods for app.controller<br /><br />
0 commit comments