Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
18 changes: 18 additions & 0 deletions 2-how-node-works/starter/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions 2-how-node-works/starter/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Esdeath/Documents/git--Jonas/complete-node-bootcamp/2-how-node-works/starter",
"program": "c:/Users/Esdeath/Documents/git--Jonas/complete-node-bootcamp/2-how-node-works/starter/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
60 changes: 60 additions & 0 deletions 2-how-node-works/starter/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": ["*", "**/*"],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"*.embeddedhtml": "html",
"SHUBHAM4.C": "cpp"
}
}
44 changes: 44 additions & 0 deletions 2-how-node-works/starter/event-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const EventEmitter = require("events");
const http = require("http");
class Sales extends EventEmitter {
constructor() {
super();
}
}

const myEmitter = new EventEmitter();

myEmitter.on("newSales", () => {
console.log("There as a slae");
});

myEmitter.on("newSales", () => {
console.log("Costumere");
});

myEmitter.on("newSales", (stock) => {
console.log(`There aer now ${stock} items left in stock.`);
});

myEmitter.emit("newSales", 9);

////////////////////

const server = http.createServer();

server.on("request", (req, res) => {
console.log("Request revievd");
console.log(req.url);
res.end("Request received");
});

server.on("request", (req, res) => {
console.log("Another requst 😊");
});
server.on("close", () => {
console.log("Server closed");
});

server.listen(8000, "127.0.0.1", () => {
console.log("Waiting for requesetes...");
});
58 changes: 58 additions & 0 deletions 2-how-node-works/starter/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require("fs");
const crypto = require("crypto");

const start = Date.now();

process.env.UV_THREADPOOL_SIZE = 4;

setTimeout(() => console.log("Timer 1 finished"), 0);
setImmediate(() => console.log("Immediate 1 finished"));

console.log("Hello from the top-level code");

fs.readFile("style.css", () => {
console.log("I/O finished");

console.log("--------------------");

setTimeout(() => console.log("Timer 2 finished"), 0);
setTimeout(() => console.log("Timer 3 finished"), 3000);

setImmediate(() => console.log("Immediate 2 finished"));
process.nextTick(() => console.log("Process.nextTick"));

crypto.pbkdf2Sync("password", "salt", 100000, 1024, "sha512");
console.log(`${Date.now() - start} - Password encrypted`);
crypto.pbkdf2("password", "salt", 100000, 1024, "sha512", () => {
console.log(`${Date.now() - start} - Password encrypted`);
});
crypto.pbkdf2("password", "salt", 100000, 1024, "sha512", () => {
console.log(`${Date.now() - start} - Password encrypted`);
});
});
//////////////////////////////
const EventEmitter = require("events");
const http = require("http");

// Custom EventEmitter class
class Sales extends EventEmitter {
constructor() {
super();
}
}

const myEmitter = new EventEmitter();

myEmitter.on("newSales", () => {
console.log("There was a sale");
});

myEmitter.on("newSales", () => {
console.log("Customer");
});

myEmitter.on("newSales", (stock) => {
console.log(`There are now ${stock} items left in stock.`);
});

myEmitter.emit("newSales", 9);
17 changes: 17 additions & 0 deletions 2-how-node-works/starter/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// console.log(arguments);
// console.log(require("module").wrapper);

// module.export
const C = require("./test-module-1");
const clac1 = new C();
console.log(clac1.add(4, 6));

//export
// const calc2 = require("./text-module-2");
const { add, multiply } = require("./test_module-2");
console.log(multiply(2, 5));

//caching
require("./test_module-3")();
require("./test_module-3")();
require("./test_module-3")();
33 changes: 33 additions & 0 deletions 2-how-node-works/starter/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fs = require("fs");
const server = require("http").createServer();

server.on("request", (req, res) => {
// Solution 1
// fs.readFile("test-file.txt", (err, data) => {
// if (err) console.log(err);
// res.end(data);
// });

// Solution 2
// const readable = fs.createReadStream("tests-file.txt");
// readable.on("data", (chunk) => {
// res.write(chunk);
// });
// readable.on("end", () => {
// res.end();
// });
// readable.on("error", (err) => {
// console.log(err);
// res.statusCode = 500;
// res.end("File not found!");
// });

// Solution 3
const readable = fs.createReadStream("test-file.txt");
readable.pipe(res);

});

server.listen(8000, "127.0.0.1", () => {
console.log("Listening...");
});
1 change: 1 addition & 0 deletions 2-how-node-works/starter/tempCodeRunnerFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-module-1
23 changes: 23 additions & 0 deletions 2-how-node-works/starter/test-module-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// class Calculator {
// add(a, b) {
// return a + b;
// }
// multiply(a, b) {
// return a * b;
// }
// divide(a, b) {
// return a / b;
// }
// }

module.exports = class {
add(a, b) {
return a + b;
}
multiply(a, b) {
return a * b;
}
divide(a, b) {
return a / b;
}
};
3 changes: 3 additions & 0 deletions 2-how-node-works/starter/test_module-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.add = (a, b) => a + b;
exports.multiply = (a, b) => a * b;
exports.divide = (a, b) => a / b;
3 changes: 3 additions & 0 deletions 2-how-node-works/starter/test_module-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("Hello from the module");

module.exports = () => console.log("Log this beautiful text 😗");
6 changes: 3 additions & 3 deletions 3-asynchronous-JS/final/dog-img.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://images.dog.ceo/breeds/labrador/n02099712_7411.jpg
https://images.dog.ceo/breeds/labrador/n02099712_6644.jpg
https://images.dog.ceo/breeds/labrador/n02099712_4705.jpg
https://images.dog.ceo/breeds/labrador/n02099712_7605.jpg
https://images.dog.ceo/breeds/labrador/n02099712_7608.jpg
https://images.dog.ceo/breeds/labrador/n02099712_7866.jpg
17 changes: 17 additions & 0 deletions 3-asynchronous-JS/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require("fs");
const superganet = require("superagent");

fs.readFile(`${__dirname}/dog.txt`, (err, data) => {
console.log(`Bread: ${data}`);
superganet
.get(`https://dog.ceo/api/breeds${data}/images/random`)
.end((err, res) => {
if (err) return console.log(err.message);
console.log(res.body.message);

fs.writeFile("dog-image.txt", res.body.message, (err) => {
if (err) return console.log(err.message);
console.log("Random dog image saved to file!");
});
});
});
16 changes: 16 additions & 0 deletions 3-asynchronous-JS/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 3-asynchronous-JS/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions 3-asynchronous-JS/node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading