Skip to content

Commit

Permalink
Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantsaini2331 authored Sep 5, 2024
1 parent 1c92bb4 commit 2adcd70
Show file tree
Hide file tree
Showing 58 changed files with 14,138 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Node/lec 68/2ndfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


const {add , multiply} = require("./calFun.js")
let result = multiply(2, 3);
console.log(result);
20 changes: 20 additions & 0 deletions Node/lec 68/calFun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

function add(a, b) {
return a + b;
}

function multiply(a, b) {
return a * b;
}


export default {add , multiply} // esm

// module.exports = { multiply, add }; //cjs


// setTimeout(() => {
// console.log(module)
// } , 1000)

// console.log(module)
34 changes: 34 additions & 0 deletions Node/lec 68/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// console.log("kya hal hai bhai ke")

// console.log(process.env)

// let num1 = process.argv[2];
// let num2 = process.argv[3];

// console.log(Number(num1) + Number(num2))

// console.log(process.argv1)

// console.log("hello clg")
// process.stdout.write("hello process \n")
// process.stdout.write("hello process")

// console.log("hello")

// process.exit(1)

// console.log("hello 2")

// console.log(__dirname)
// console.log(__filename);

// const { add } = require("./calFun.mjs");

// console.log(addFun)

import add from "./calFun.js"

// console.log(add)

let result = add.add(4, 5);
console.log(result);
3 changes: 3 additions & 0 deletions Node/lec 68/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
3 changes: 3 additions & 0 deletions Node/lec 69/ABC.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello ji
hello ji
hello ji
Empty file added Node/lec 69/ffg/sdf.js
Empty file.
88 changes: 88 additions & 0 deletions Node/lec 69/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const fs = require("fs");
const os = require("os")

// console.log(__dirname +"/abc.txt")
// console.log(__dirname +"abc.txt")
// const res = fs.writeFileSync(__dirname +"/abc.txt" , "hello sir ")
// const res = fs.writeFileSync(`${__dirname}/abc.txt` , "hello sir ji ")

// fs.writeFile(`${__dirname}/abc.txt` , "hello sir ji " ,function (err){
// if (err) throw err;
// console.log('The file has been saved!');
// })

// console.log(fs)

// console.log("1")
// const data = "a".repeat(500 * 1024 *1024)
// let data2 = fs.writeFileSync("abc.txt" , data)
// // console.log(data)
// console.log("2")

// console.log("1");
// const data = "a".repeat(500 * 1024 * 1024);
// fs.writeFile("abc.txt", data, (err) => {
// if (err) {
// console.log(err);
// } else {
// console.log("manla done hai");
// }
// });

// console.log("2");

// console.log("1")
// fs.readFile("abc.txt" , "utf-8" , (err, data) => {
// if(err) throw err;
// else {
// console.log(data)
// }
// })

// console.log("2")

// fs.unlink("hello.js") //delete file

// fs.appendFile("abc.txt", "hello ji \n" , (err) => {
// if(err) throw err;
// console.log("done")
// })

// fs.copyFile("abc.txt" ,"xyz.txt" )

// fs.mkdir("hello/anotherfile.js", {recursive : true} ,(err, path) => {
// if (err) throw err;
// else {
// console.log(path);
// }
// });

// fs.rm("hello" , {recursive : true})

// console.log(__dirname)
// console.log(__dirname.replace("lec 69", "lec 68"))

// fs.readdir(__dirname.replace("lec 69", "lec 68"), {encoding : "utf-8" ,recursive :true }, (err, file) => {
// if (err) throw err;
// else console.log(file);

// });


// const rezs = fs.readdir("ffg" , { withFileTypes : true}, (err, file) => {

// console.log(file)
// })




// fs.rename("abc.txt", "ABC.txt")

// const res = fs.readdirSync(__dirname.replace("lec 69", "lec 68") , {withFileTypes :true})
// console.log(res)

// console.log(os.cpus().length)
// console.log(os.arch())


3 changes: 3 additions & 0 deletions Node/lec 69/xyz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello ji
hello ji
hello ji
11 changes: 11 additions & 0 deletions Node/lec 70/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: aquamarine;">
<h1 style="text-align: center ; margin: 20px;">[path]</h1>
</body>
</html>
27 changes: 27 additions & 0 deletions Node/lec 70/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const http = require("http");
const fs = require("fs");

const server = http.createServer(function (req, res) {
let filePath = __dirname + "/index.html";

// console.log(req.url)

if (req.url == "/" || req.url == "/about"|| req.url == "/contactus") {
let path = req.url.split("/")[1].toUpperCase();
console.log(req.method)
fs.readFile(filePath, { encoding: "utf-8" }, (err, data) => {
if (err) {
throw new Error("Not found");
} else {
data = data.replace("[path]" , path == "" ? "Code thread" : path)
res.end(data);
}
});
} else {
return res.end(JSON.stringify({ message: "not found" }));
}
});

server.listen(3000, () => {
console.log("server started");
});
11 changes: 11 additions & 0 deletions Node/lec 71/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: aquamarine;">
<h1 style="text-align: center ; margin: 20px; text-transform: capitalize;">[path]</h1>
</body>
</html>
61 changes: 61 additions & 0 deletions Node/lec 71/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const express = require("express");
const app = express();
const path = require("path");
const fs = require("fs");

// app.METHOD(path , handler)

function dynamicData(req, res, route) {
fs.readFile(__dirname + "/index.html", { encoding: "utf-8" }, (err, data) => {
if (err) {
throw new Error("Not found");
} else {
data = data.replace("[path]", route == "" ? "Code thread" : route);
res.send(data);
}
});
}

// app.get("/", (request, response) => {
// // console.log("hello");
// // response.json({ message: "hello ji" });
// dynamicData(request, response, "");
// });

// app.get("/contactus", (request, response) => {
// dynamicData(request, response, "contactus");
// });

// app.get("/about", (request, response) => {
// dynamicData(request, response, "about");
// });

app.get([ "/" , "/about" , "/contactus"], (request, response) => {
let path = request.url.split("/")[1]
fs.readFile(__dirname + "/index.html", { encoding: "utf-8" }, (err, data) => {
if (err) {
throw new Error("Not found");
} else {
data = data.replace("[path]" , path == "" ? "Code thread" : path)
response.send(data);
}
})
});

// app.use()

// app.post("/", (req, res) => {
// res.send("hello");
// });

// app.put("/user", (req, res) => {
// res.send("Got a PUT request at /user");
// });

// app.delete("/user", (req, res) => {
// res.send("Got a DELETE request at /user");
// });

app.listen(3000, () => {
console.log("chl gaya bhaiye server");
});
Loading

0 comments on commit 2adcd70

Please sign in to comment.