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
Copy file name to clipboardExpand all lines: README.md
+387Lines changed: 387 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,193 @@ Some other global object are
125
125
- //Reports
126
126
- //Process
127
127
128
+
## Day 4 - ECMA Script
129
+
130
+
ECMA was created to standardize JavaScript to help foster multiple independent implementations.
131
+
The full form of ECMA is European Computer Manufacturer's Association.A standard for scripting languages like JavaScript, JScript is ECMAScript.
132
+
133
+
Here NodeJS follow the ECMA standard, here we are going to dicuss about Const, Let and class.
134
+
> <b>let :</b> Unlike variables declared with var that are function-scoped, variables declared with let are block-scoped: they only exist in the block they are defined in.
135
+
136
+
```ruby
137
+
var a =20
138
+
var a =30;
139
+
140
+
console.log(a);
141
+
142
+
let x =20;
143
+
x ="satya"; /// but you can change the datatype
144
+
//let x =30; ///if you will defined like that it will give error
145
+
146
+
console.log(x);
147
+
var v = () => {
148
+
let x =50; /// here again you can defined it and it will work like scoped variable.
|variables belong to the global scope or local scope if they are declared inside a function: var counter;| The let variables are blocked scopes: let counter; |
160
+
|var variables are added to the global object as properties. The global object is window on the web browser and global on Node.js: |However, the let variables are not added to the global object|
161
+
|The var keyword allows you to redeclare a variable without any issue.| If you redeclare a variable with the let keyword, you will get an error|
162
+
163
+
164
+
> <b>Const :</b> Variables defined with const behave like let variables, except they cannot be reassigned. <br />
165
+
166
+
If we assign a primitive value to a constant, we cannot change the primitive value:
167
+
168
+
169
+
```ruby
170
+
const a =30;
171
+
//a =40; // you can not assign the a to another value
172
+
173
+
console.log(a);
174
+
175
+
```
176
+
177
+
You can change the properties of a constant object:
178
+
179
+
```ruby
180
+
181
+
// but if you defined the object and want to change the value of it tha you can do that
> <b>Class :</b> Its type of function, but instead of using function keyword to initiate it, here use the keyword class, and the properties are assigned inside a constructor() method. <br />
194
+
195
+
```ruby
196
+
classTestUserClass
197
+
{
198
+
constructor()
199
+
{
200
+
this.name ="Satya first ";
201
+
this.phoneNumber ="6776777"
202
+
}
203
+
204
+
getName()
205
+
{
206
+
//console.log(name); // this will give error to access any of the class values you need to use thi.
207
+
console.log(this.name);
208
+
this.age =12
209
+
return this.name;
210
+
}
211
+
212
+
getAge()
213
+
{
214
+
return this.age;
215
+
}
216
+
}
217
+
218
+
219
+
var tc =newTestUserClass();
220
+
//tc.getName();
221
+
console.log(tc.getAge()); // you need to call the Get name first as the Age setting their.
222
+
```
223
+
224
+
## Day 5 - Prototype
225
+
226
+
In the previous chapter we learned how to use an object constructor.
227
+
228
+
Sometimes you want to add new properties (or methods) to all existing objects of a given type.
229
+
Sometimes you want to add new properties (or methods) to an object constructor.
230
+
231
+
Prototype property in Javascript allows you to add new properties to object constructors.
232
+
233
+
```ruby
234
+
// prototype usese to extend the functionalty of exiting function.
235
+
236
+
var Employee= function()
237
+
{
238
+
this.name ="Satya";
239
+
this.age =30;
240
+
241
+
242
+
}
243
+
244
+
245
+
var e =newEmployee();
246
+
console.log(e.age);
247
+
248
+
Employee.prototype = {
249
+
phoneNumber : "4545454",
250
+
251
+
GetAge : function()
252
+
{
253
+
return this.name;
254
+
}
255
+
}
256
+
257
+
var e =newEmployee();
258
+
console.log(e.age);
259
+
console.log(e.phoneNumber);
260
+
console.log(e.GetAge());
261
+
```
262
+
263
+
## Day 6 - Modules
264
+
265
+
1. Instead of keeping all the code in one file we split the code into multiple file.
266
+
2. To splitting the file into mutiple file we defined it as modules.
267
+
3. You can create your own modules, and easily include them in your applications.
268
+
4. It will be useful for code resuability and for maintability. <br /><br />
269
+
270
+
Creating a samall calculator with is having addition, substartion and defined all in different file<br />
271
+
272
+
<b> addition.js </b>
273
+
274
+
```ruby
275
+
//Additionmodule which need to export.
276
+
277
+
module.exports = {
278
+
279
+
Addition : function(a,b)
280
+
{
281
+
return a + b;
282
+
}
283
+
284
+
}
285
+
```
286
+
287
+
<b> subtration.js </b>
288
+
289
+
```ruby
290
+
// you can define the modules like that as well as.
291
+
//We define modules into two type.
292
+
293
+
var subtration = function(a,b)
294
+
{
295
+
return a -b;
296
+
}
297
+
298
+
module.exports.subtration = subtration;
299
+
```
300
+
301
+
<b> Calculator.js </b> < br/>
302
+
Need to use require to export the module.
303
+
304
+
```ruby
305
+
// exporting both of the module using require.
306
+
307
+
var add =require("./addition");
308
+
var sub=require("./subtration");
309
+
310
+
console.log(`Addition of number 10 and 12 : ${add.Addition(10, 12)}`);
311
+
console.log(`Subtration of number 14 and 12 : ${sub.subtration(14, 12)}`);
312
+
```
313
+
314
+
128
315
## Day 10 - ExpressJs
129
316
130
317
ExpressJs use to build the Node Application, it make faster the devlopment and provide inbuild code for development.<br /><br />
@@ -529,3 +716,203 @@ Plug that method which we need to attach that middle ware
529
716
})
530
717
531
718
```
719
+
720
+
## Day 17 - NestJs
721
+
722
+
```https://docs.nestjs.com/``` <br />
723
+
- It is used to build serverside application microservices and RestAPI.
724
+
- It is proper framework like Asp.net, Django. It is provide you the architecture to build a server.
725
+
- It is Extensible, Versatile and prograssive javascript.
726
+
- If you are working with NestJs, type script is the default module. If you have worked with angular than NEST js is pretty similar.
727
+
- Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!
728
+
- Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications.
- Nest is database agnostic, allowing you to easily integrate with any SQL or NoSQL database
733
+
- You can also directly use any general purpose Node.js database integration library or ORM,
734
+
- Nest provides tight integration with TypeORM and Sequelize out-of-the-box with the @nestjs/typeorm and @nestjs/sequelize packages respectively, @nestjs/mongoose package for mango DB.
- Passport is the most popular node.js authentication library, well-known by the community and successfully used in many production applications. It's straightforward to integrate this library with a Nest application using the @nestjs/passport module
738
+
At a high level, Passport executes a series of steps to:
739
+
a) Authenticate a user by verifying their "credentials" (such as username/password, JSON Web Token (JWT), or identity token from an Identity Provider)
740
+
b)Manage authenticated state (by issuing a portable token, such as a JWT, or creating an Express session)
741
+
c)Attach information about the authenticated user to the Request object for further use in route handlers
- Nest comes with a built-in text-based logger which is used during application bootstrapping and several other circumstances such as displaying caught exceptions (i.e., system logging). This functionality is provided via the Logger class in the @nestjs/common package.
- Nest also provides compatibility with other libraries such as, for example, Fastify.
748
+
Fastify provides a good alternative framework for Nest because it solves design issues in a similar manner to Express. However, fastify is much faster than Express, achieving almost two times better benchmarks results.
GraphQL is a powerful query language for APIs and a runtime for fulfilling those queries with your existing data. It's an elegant approach that solves many problems typically found with REST APIs.
753
+
- GraphQL queries access not just the properties of one resource but also smoothly follow references between them. While typical REST APIs require loading from multiple URLs, GraphQL APIs get all the data your app needs in a single request. Apps using GraphQL can be quick even on slow mobile network connections.
- Nest natively supports the microservice architectural style of development.In Nest, a microservice is fundamentally an application that uses a different transport layer than HTTP.
757
+
Nest supports several built-in transport layer implementations, called transporters, which are responsible for transmitting messages between different microservice instances. Most transporters natively support both request-response and event-based message styles.
- 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
+
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