Friday, 21 May 2021

NodeJS

 NODE js



  • Node JS is a open source environment
  • It's  sever side isn't a programming language
  • It's helps to run Javascript code on sever side
  • It's support all 0S
  • Very Fast 
  • It's has Single threaded  module
  • No buffering data
  • Non blocking and Asynchronous
  • Runtime environment With Javascript Library 

Modules
  • Node JS  modules same as Javascript Libraries.
  • Node JS has lot of built in modules
  • You can create your own modules 

Note:- If you you want to include the in-build modules or your own modules in your application then you use the require() function with the name of the  module 


Built in Modules

  • http:-To Connect http server
  • https:-To Connect https server 
  • fs:- To Handle file system
  • events:-To Handle events
  • path:- To Handle file Paths
  • url:-To parse url string 

HTTP Work Method

  • HTTP stands for Hyper Text Transfer Protocol
  • WWW stands for World Wide Web
  • WWW is about communication between web clients and server
  • Its done by sending HTTP requests and receiving HTTP responses
  • A client (Browser) sends HTTP request to the web
  • And web server receives the request
  • The server  runs an application to process the request
  • The  server returns an HTTP response to the browser
  • The client receives the response.

HTTP MODULE

  • Use  require directive to load Node JS modules.
  • HTTP module is a build in module of Node JS,Which allows Node JS to transfer data over the hyper text Transfer Protocol
  • The HTTP module use the createServer() Method to create an HTTP server 
  • If the response from the HTTP server is supposed to be displayed as HTML ,you should include an HTTP header with a content type.
       The first argument of the res.writeHead() is the status code,200 means success, the second argument is an object containing the response headers.

  • HTTP server that listens to server ports and gives a response back to the client.
  • The function passed into the http.createServer() method,will be executed when someone tries to access the computer on port 8080

File System Module

  • Import file system module using require keyword
                    EX:- const fs = require('fs');
  • The Node JS file system module allows to create,read,write,update,delete or rename the files on your computer
  •  Inside the callback function we pass the first parameters as err for printing the error message when the file have an error.
 

URL Module

  • URL module  splits up a web address into readable parts.
  • Parse an address with the url.parse() method,and it will splite a URL object with each part of the address as properties 
http://localhost:8080/Ann.html
  • Host: localhost:8080
  • Path name: Ann.html
Note:- Web servers usually respond with html documents along with images,style sheets and scripts.


Send Gmail Using Node JS

  • We can use Nodemailer Module to send Gmail from our system.
  • We have to install Nodemailer from npm using "npm install nodemailer"comand
  • You can compose  a mail in various format such as text,html.