Skip to content

Commit e9562d9

Browse files
committed
nodejs and reactjs
1 parent fee8db6 commit e9562d9

File tree

187 files changed

+121137
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+121137
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// const fs=require('fs')
2+
// const http=require('http')
3+
// const server=http.createServer()
4+
// server.on('request',(req,res)=>{
5+
// const rstream=fs.createReadStream("test1.txt")
6+
// rstream.on('data',(chunkdata)=>{
7+
// res.write(chunkdata)
8+
// })
9+
// rstream.on('end',()=>{
10+
// res.end()
11+
// })
12+
// rstream.on('error',(err)=>{
13+
// console.log(err)
14+
// res.end("file not found")
15+
// })
16+
// })
17+
// server.listen(8000,"127.0.0.1")
18+
19+
20+
const zlib = require('zlib')
21+
const fs = require('fs')
22+
const gzip = zlib.createGzip()
23+
const inp = fs.createReadStream('input.txt')
24+
const out = fs.createWriteStream('input.txt.gz')
25+
inp.pipe(gzip).pipe(out)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// // Synchronous
2+
// const fs = require('fs')
3+
// fs.writeFileSync('text.txt','this is os module') // this creates a text file
4+
// // node filename.js -> then it will create a file with content
5+
6+
// try{
7+
// fs.rmSync('new.txt');
8+
// fs.copyFileSync('text.txt','text2.txt')
9+
// // using try catch
10+
// console.log('Data copied')
11+
// }
12+
// catch(err){
13+
// console.error('one of the file is missing')
14+
// }
15+
// // console of node and console of browser are different in nature
16+
17+
// fs.renameSync('text.txt','text1.txt') // rename the file name
18+
// // deleting the file : -
19+
// fs.rm('text2.txt')
20+
21+
// // Asynchronous
22+
// const fs = require('fs')
23+
// fs.writeFile("text.txt","This is Asych Mod",()=>{
24+
// console.log("done")
25+
// });
26+
// fs.readFile("text.txt","utf-8",(err,data)=>{
27+
// console.log(data)
28+
// }); // read file contents
29+
30+
// fs.appendFile("text.txt","new Content Added",()=>{
31+
// console.log("done")
32+
// });
33+
// //copyfile
34+
// fs.copyFile("text.txt","text12.txt",function(err){
35+
// if(err)return console.log('file is missing')
36+
// console.log("data copied")
37+
// });
38+
// // delete file
39+
// fs.unlink("text12.txt",function(err){
40+
// if(err)return console.log('file is missing')
41+
// console.log("deleted")
42+
// });
43+
44+
//-------------------------------------------------------//
45+
46+
// OS MODULES METHODS : -
47+
// const os = require('os')
48+
// console.log(os.arch()) //architecture
49+
// console.log(os.freemem()) // free memory
50+
// console.log(os.hostname())
51+
// console.log(os.tmpdir())
52+
// console.log(os.type())
53+
// console.log(os.platform())
54+
55+
//path module
56+
// const path= require('path')
57+
// console.log(path.parse("/Users/turwash/Desktop/Backend Class/1March.js"))
58+
// const mypath=path.parse("/Users/turwash/Desktop/Backend Class/1March.js")
59+
// console.log(mypath.name)
60+
61+
// we can create our own modules as well
62+
// const add = (a,b)=>{
63+
// return a + b ;
64+
// }
65+
66+
// const sub = (a,b)=>{
67+
// return a - b ;
68+
// }
69+
70+
// const mul = (a,b)=>{
71+
// return a * b ;
72+
// }
73+
// const name = 'Turwash'
74+
75+
// // module.exports.add= add;
76+
// // module.exports.sub= sub;
77+
// // module.exports.mul= mul;
78+
79+
// // OBJECT DESTRUCURE
80+
// module.exports={add,sub,mul}
81+
82+
83+
84+
85+
// path.delimeter property
86+
const path1 = require('path1')
87+
console.log(process.env.path1)
88+
console.log(process.env.path1.split(path1.delimiter))
89+
90+
293 KB
Binary file not shown.
197 KB
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Errror handling using try , catch -> all the paramteresd 3 ,
2+
// Finally, throw and block
3+
4+
5+
// two properties of error object
6+
7+
8+
9+
10+
11+
// using throw : -
12+
13+
function divideByZero(num) {
14+
try {
15+
if (num === 0) {
16+
throw "Cannot divide by zero";
17+
} else {
18+
return 10 / num;
19+
}
20+
} catch (error) {
21+
console.log("Error: " + error);
22+
}
23+
}
24+
25+
console.log(divideByZero(5));
26+
console.log(divideByZero(0));
27+
28+
29+
523 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Express notes :
2+
// Normal sending of message: -
3+
4+
1) npm init -y (we initialized our express , this will create Package.json).
5+
2) Then we create index.js where we will write our codes.
6+
3) To install express we used -> npm install express --save (This installs Express and also created node_modules, package-lock.json).
7+
4) We can also add node_modules : npm i or npm install
8+
5) Uninstall express : npm uninstall express
9+
10+
// Sending html file : -
11+
6) Now we are creating Html file and adding it
12+
7) To install Nodemon in our system we use -> npm install -g nodemon
13+
14+
// Sending JSON File :-
15+
8)
16+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Bootstrap demo</title>
7+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
8+
</head>
9+
<body>
10+
<nav class="navbar navbar-expand-lg bg-body-tertiary">
11+
<div class="container-fluid">
12+
<a class="navbar-brand" href="#">Navbar</a>
13+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
14+
<span class="navbar-toggler-icon"></span>
15+
</button>
16+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
17+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
18+
<li class="nav-item">
19+
<a class="nav-link active" aria-current="page" href="#">Home</a>
20+
</li>
21+
<li class="nav-item">
22+
<a class="nav-link" href="#">Link</a>
23+
</li>
24+
<li class="nav-item dropdown">
25+
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
26+
Dropdown
27+
</a>
28+
<ul class="dropdown-menu">
29+
<li><a class="dropdown-item" href="#">Action</a></li>
30+
<li><a class="dropdown-item" href="#">Another action</a></li>
31+
<li><hr class="dropdown-divider"></li>
32+
<li><a class="dropdown-item" href="#">Something else here</a></li>
33+
</ul>
34+
</li>
35+
<li class="nav-item">
36+
<a class="nav-link disabled">Disabled</a>
37+
</li>
38+
</ul>
39+
<form class="d-flex" role="search">
40+
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
41+
<button class="btn btn-outline-success" type="submit">Search</button>
42+
</form>
43+
</div>
44+
</div>
45+
</nav>
46+
47+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
48+
</body>
49+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Creating own server using Express
2+
3+
const express = require('express');
4+
const path = require('path');
5+
const app = express();
6+
const port = 3000;
7+
8+
app.get('/',(req,res)=>{
9+
res.send("Congratulations Turwash, You have Sucessfully Created The Server !! ");
10+
})
11+
12+
app.get('/about',(req,res)=>{
13+
// res.send("Welcome to your About Page !! ");
14+
// res.sendFile(path.join(__dirname, 'index.html'));
15+
// res.status(500) // error status send
16+
17+
// for json
18+
res.json({"Turwash" : 27});
19+
})
20+
21+
app.get('/contact',(req,res)=>{
22+
res.send("Contact Me @9693182173!! ");
23+
})
24+
25+
app.listen(port,()=>{
26+
console.log(`Listening to the port at -> http://localhost:${port}`);
27+
})
28+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// const details = {
2+
// name : "Turwash",
3+
// college : "Lpu"
4+
// }
5+
6+
// // console.log(details)
7+
8+
// const deatils1 = JSON.stringify(details)
9+
// console.log(deatils1)
10+
11+
// const deatils2 = JSON.parse(deatils1)
12+
// console.log(deatils2)
13+
14+
15+
// ---------------
16+
17+
const fs = require('fs')
18+
const details = {
19+
name : "Turwash",
20+
college : "Lpu"
21+
}
22+
const jsondata = JSON.stringify(details)
23+
fs.writeFile("json1.js",jsondata,(err)=>{
24+
console.log("Done")
25+
})
26+
27+
fs.readFile("json1.js","utf-8",(err,data)=>{
28+
const jsonparsed = JSON.parse(data);
29+
console.log(data)
30+
console.log(jsonparsed)
31+
})
32+

0 commit comments

Comments
 (0)