0% found this document useful (0 votes)
23 views18 pages

Downloading React Components as PDF

Uploaded by

Manoj Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views18 pages

Downloading React Components as PDF

Uploaded by

Manoj Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MERN - React js

React: React js one of the most popular front-end lib

-Developing UI Components

-Maintain and managed by Facebook

Pre-request:

HTML

CSS

Java Script

MERN - MVC Architecture

M- Model(Database, Mongo DB)

V- View - React js

C- Controller

Software:
Visual studio Code

node

Mongo DB

Difference b/w Angular & React


-Angular have more concept than react

-Angular is complex than our react

-Both are equal opportunity

In visual studio code :


-project path

-node -v

-npm -v
react & react DOM:
-npm install react react-dom --save

web pack:
-npm install webpack webpack-dev-server webpack-cli --save

create a react project:


- npx create-react-app anuproject

-cd anuproject

Run:
-npm start

Local: [Link]

On Your Network: [Link]

React Components:
React component is the building block of react application.

Function Component:
easy way to return our components

Example :

function App() {

return (

<div className="App">

<img src="[Link]

</div>

);

Class component:
class component is more complex than function component

-render method
-return method

Example :

class App extends [Link]{

render(){

return(

<div>

<h1>Hello Everyone</h1>

</div>

React State :
-updatable data structure

-contain the information about components

-value can be change

Example :

class App extends [Link]{

constructor(){

super();

[Link]={name:"iygygyg"};

render(){

return(

<div><h1>ftyft uygygyugyg</h1>{[Link]}</div>

React Props :
Calculator project :

Function App(){
Const[value,setValue]=useState(‘ ’);
Return( <div className=”container”>
<form action=””>
<input type=”text” value={value} />
<div>
<input type=”button” value=”1” onClick={e=>setValue(value +[Link])} />
<input type=”button” value=”2” onClick={e=>setValue(value +[Link])} />
<input type=”button” value=”3” onClick={e=>setValue(value +[Link])} />
<input type=”button” value=”+” onClick={e=>setValue(“”)} />

<input type=”button” value=”=” className=”equal”


onClick={e=>setValue(eval(value))} />
</div>
</form>
</div>)
}

NODE JS

Create server

Example :

let z=require("http");

[Link](function(req,res){

[Link](200,{"content-type":"text/html"});

[Link]("<h1>gtugyu ygygyu</h1>");

}).listen(8085);

NODE JS Object :

let pavithra={

mark:80,

addr:"karur"

[Link]([Link]);

[Link]([Link]);

USER DEFINE BUILDIN OBJECT :

function demo(){

[Link]("hello everyone");
}

let z={

output:demo,

name:"pavithra"

[Link]();

[Link]([Link]);

[Link]([Link]);

[Link](Math.SQRT2);

NODE JS JSON :

ARRAY
 collection of similar data and also used to store multiple values.

// create an array

let live=["pavithra","vicky","sangavi"];

[Link](live[0]);

// upadte value in array

live[1]="anup";

[Link](live[1]);

// push method to add data at last

[Link]("anup");

[Link](live);

// pop method to remove the data in array


[Link]();

[Link](live);
// to find length of an array
[Link]([Link]);

NODE JS FUNCTION :
 A function is a group of statements that together perform a task

Example :
function demo(z){

[Link](`helo, ${z}`);

demo("pavithra");

HIGHER ORDER FUNCTION :


A higher order function is a function that takes one or more functions as arguments, or returns a
function as its result.

Example :
function add(a,b,callback){

return callback(a,b);

function multiply(a,b){

return a+b;

[Link](add(12,2,multiply));

NODE JS OPERATOR

NODE JS LOOP

NODE JS CLASS
constructor function

function Demos(name,age){
[Link]=name;
[Link]=age;
}
const z1=new Demos("pavithra",30);
[Link]([Link]);
[Link]([Link]);

EXCEPTION HANDLING :
Exception Handling in Java or Java Exceptions with checked, unchecked and errors with
example and usage of try, catch, throw, throws and finally keywords.

Example :
function Democ(){
throw new Error("error msg");
}
try{
Democ();
}catch(e){
[Link]([Link]);
} finally {
[Link]("demo");
}

NODE JS GLOBALS

NODEJS Asynchronous Function *


function Demoss(){
// set timeout function
setTimeout(function(){
[Link]("pavithra");
},9000);
[Link]("hello everyone");
}
Demoss();

NODE JS WEB
 HTTP Response code
200 – ok
400 – bad request
401 – unautorized
404 – not found
500 – server error
501 – server unavailable

BUFFER :
Buffer is used to Convert all out data into binary datas or numbers.
Example :

String used:
var zm=new Buffer("pavithra");
[Link](zm);

Number used :
var zm=new [Link](10);
[Link](zm);

NODE JS PROCESS :
What are the things we need to excute the program in the terminal.

// process

function addd(a){
let b=0;
for(let x of a){
b+=x;
}
return b;
}
// command line arguments
const l=addd([3,5,6,2]);
[Link](l);

NODE JS SETTIMEOUT AND SET INTERVAL :


Diff between set timeout and set interval :
SET TIMEOUT :
setTimeout(function(){
[Link]("pavithra");
},9000);
SET INTERVAL :
let a1=12;
let mydata=setInterval(function(){
[Link]("pavithra");
a1++;
[Link](a1);
if(a1==20){
clearInterval(mydata);
}
},2000);

Body Parser : ( library )


Src :
- npm install body-parser
Express intsall :
- npm install express
EJS install :
- npm install ejs
If I click submit button the body parser to get the input from the user
and request to server.
Template engine :
Help us to create a dynamic page ( EJS => embedded javascript )

Create ejs file : ( [Link] )


Example :
[Link] :
const bodyparser=require('body-parser');
const express=require('express');
const path=require('path'); // add libraries

const app=express(); // connect express


let port=[Link] || 8081
// set port
// set engine
// engine where the ejs file then its the default index file in express
[Link]("views",[Link](__dirname));
[Link]("views engine","ejs");

// add bp
[Link]([Link]({extended:true}));
[Link]([Link]());

// add routing

[Link]("/",function(req,res){
[Link]("home");
});

[Link]("/data",function(req,res){
[Link]("your name",[Link]);
});
[Link](port);
[Link] :
<html>
<head></head>
<body>
<form method="post" action="data">
<input type="text" name="name" id="" placeholder="enter
your name" required ><br>
<button type="submit">submit</button>
</form>
</body>
</html>

MODULE :
Collection of functionality present in it.
File Module :
let z=require("fs"); // work on file system

// read file
[Link]("[Link]",function(error,data){
if(error) throw error;
[Link]([Link]());
});

// write operation
[Link]("[Link]","helo pavithra",function(err,data){
if(err) throw err;
[Link]("file done");
})

PATH MODULE :
let z=require("path");
// to find which folder you are
var a=[Link]("C:\\node\\[Link]");

// to find which extension you are


var b=[Link]("C:\\node\\[Link]");
[Link](a);
[Link](b);

Bcrypt Module :
bcrypt is a type of cryptographic algorithm used to securely store passwords. It scrambles a
user's password into a unique code. This way, even if a thief takes the database, they won't
be able to recover the original passwords readily.

Install bcrypt :
- npm install bcryptjs

let c=require("bcryptjs");
var pname="pavithra";
var bv;
// genSalt is rounting the value
// hash is provide random values

[Link](10,function(err,result){
[Link](pname,result,function(err,hash){
if(err) throw err;
bv=hash;
[Link](hash);
});
});

NODE JS OS MODULE :
let z=require("os");

[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());

NODE JS UTIL :
var z=require("util");

var name="sukumar";
var age=28;
var rank=5;

var a=[Link]('name is %s',name);


var b=[Link]('age is %d',age);
[Link](a);
[Link](b);

[Link] :
- its contains info about our project what is the module use and what is the version

MODE PACKAGE MANAGER ( NPM )


NPM JSON

NODE JS ACTION EVENT : *


Set timeout function also the action event :
[Link]("uytftf uygygyg");
[Link]("igygyg uygygy ugyugygy");
setTimeout(function(){
[Link]("jhgyg uygygyg uygygyg")
},5000);

EVENT LOOP : *
[Link]("uytftf uygygyg");
[Link]("igygyg uygygy ugyugygy");
setTimeout(function(){
[Link]("jhgyg uygygyg uygygyg")
},5000);

NODE JS STREAM :
let z=require("fs");
var data="";
// read
var read=[Link]("[Link]");
// find size of the data
[Link]("data",function(chunk){
data +=chunk;
});
[Link]("end",function(){
[Link](data);
});
WRITE STREAM :
let z=require("fs");
var data="hello gftft";

// write
var read=[Link]("[Link]");
[Link](data,"utf-8");
[Link]("data",function(){
[Link]("end");
});
CUSTOM STREAM : ( read data in one file and write it into another file )
let z=require("fs");
var read=[Link]("[Link]");
var read1=[Link]("[Link]");
[Link](read1);
[Link]("done");

NODE JS HTTP :
let z=require("http");

[Link](function(req,res){
[Link](200,{"content-type":"text/html"});
[Link]("<h1>gtugyu ygygyu</h1>");
}).listen(8085);
HTTP :
- its not only for server creation and its also used to create API – crud operation
HTTP Headers :
- Its contain response code
HTTP Files :
- Its contain content-type

Common questions

Powered by AI

Bcrypt in Node.js is used for securely storing passwords by hashing them instead of storing them as plain text. This is crucial for protecting user data even if the database is compromised. The process involves generating a salt using 'genSalt()', which adds a layer of randomness, and then creating a hash of the password combined with the salt using 'hash()'. This results in a unique code that is stored in the database. The bcrypt algorithm is computationally intensive, which helps protect against brute force attacks .

The path module in Node.js is a core utility that provides methods for handling and transforming file paths. It allows developers to interact with the file system in a normalized and reliable manner across different operating systems. Functions like 'basename()', 'dirname()', 'extname()', 'join()', and 'resolve()' are important for parsing path strings, constructing file paths, and ensuring compatibility. This aids in robust file system interaction, such as locating files, handling paths for file operations, and constructing proper directory structures .

Exception handling in Node.js is vital for managing runtime errors and ensuring the application remains stable. It employs try-catch blocks similar to Java, allowing developers to catch and manage exceptions efficiently. While Java uses checked and unchecked exceptions, Node.js exceptions are akin to Java's unchecked exceptions. The usage of 'throw', 'try', 'catch', and 'finally' in Node.js allows structured error handling, letting developers clean up resources or provide fallbacks without crashing the application .

HTTP status codes in Node.js applications signal the result of an HTTP request, guiding both client and server about the outcome. These codes are essential in handling API responses and debugging request handling. Common status codes include 200 (OK) indicating successful requests, 400 (Bad Request) for syntactically incorrect requests, 401 (Unauthorized) for failed authentication, 404 (Not Found) for unavailable resources, and 500 (Internal Server Error) for server-side issues. By providing precise feedback, they enable efficient communication and error handling between the client and server .

The body-parser library in a Node.js application is crucial for parsing incoming request bodies in middleware before the handlers, making the parsed data available under 'req.body'. It allows for different types of payload parsing, such as JSON and URL-encoded formats, facilitating easy access to user input from forms and dynamic content. It's commonly used when setting up an Express server to handle POST request data effectively .

The setTimeout function in Node.js executes a function once after a specified delay, while setInterval continues to execute the function at regular intervals until stopped or cleared using 'clearInterval'. SetTimeout is useful for delaying an operation, such as an API call, while setInterval can repeatedly perform tasks like polling a server or updating a UI. Both functions are important for handling asynchronous operations, allowing non-blocking execution of code .

Class components in React are generally more complex than function components as they include features like lifecycle methods and state management through the 'this' context. They make use of methods such as 'render()' and can manage their own state, which is stored in the 'this.state' object. In contrast, function components are simpler and rely on hooks like 'useState' for handling the state, which allows for a more flexible and cleaner syntax. Function components are typically easier to read and test, which has led to their increased adoption in modern React applications .

Higher-order functions in Node.js are functions that can take other functions as arguments or return them. This allows for functional programming paradigms and greater abstraction in code. For example, a function such as 'add(a, b, callback)' can be a higher-order function by taking a callback function as an argument to perform a calculation with 'a' and 'b'. In the example provided, 'add(12, 2, multiply)' passes 'multiply' as a callback function, allowing 'add' to apply any operation defined by a function passed to it .

The MVC architecture in a MERN stack application structures the application into three interconnected components: Model, View, and Controller. The Model represents the database, handled by MongoDB, which manages data storage. The View is managed by React.js, responsible for rendering the user interface. The Controller, managed by Express.js in conjunction with Node.js, handles the application logic and routes traffic between the database and UI. This separation of concerns facilitates organized code, improved scalability, and easier maintenance by decoupling data, interface, and logic .

The MERN stack is a JavaScript-centric technology stack for building dynamic web applications. It consists of four core components: MongoDB (as the database), Express.js (as the backend web framework), React.js (for building the user interface), and Node.js (as the server environment). Each plays a unique role: MongoDB stores data in a NoSQL format, allowing for flexible data manipulation; Express.js facilitates handling HTTP requests and responses; React.js enables the creation of interactive user interfaces; and Node.js acts as a server framework that allows JavaScript to be used for server-side programming .

You might also like