Skip to content

Commit 5d529a3

Browse files
committed
lecture one
1 parent ff44f91 commit 5d529a3

9 files changed

+164
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Welcome to the exciting world of Node.js! In this lecture series, we will delve into the powerful features of Node.js, its benefits, and how it simplifies server-side JavaScript development. If you already have a solid understanding of JavaScript, you'll find that Node.js is a natural extension that allows you to leverage your existing skills to build robust and scalable applications.

es6.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//arrow functions
2+
function Add(a, b) {
3+
return a + b;
4+
}
5+
const add = (a, b) => a + b;
6+
7+
////////////////////////////////
8+
// Template literals
9+
// Concatenation
10+
const name = "Alice";
11+
const age = 30;
12+
const message1 = "Welcome, " + name + "! You are " + age + " years old.";
13+
14+
// Template Literals
15+
const message2 = `Welcome, ${name}! You are ${age} years old.`;
16+
17+
////////////////////////////////
18+
// array methods
19+
const numbers = [1, 2, 3, 4, 5];
20+
numbers.filter((n) => n % 2 === 0); // [2, 4]
21+
numbers.map((n) => n * 2); // [2, 4, 6, 8, 10]
22+
numbers.reduce((total, n) => total + n, 0); // 15
23+
numbers.forEach((n) => console.log(n)); // 1 2 3 4 5
24+
numbers.find((n) => n === 3); // 3
25+
numbers.findIndex((n) => n === 3); // 2
26+
numbers.every((n) => n < 10); // true
27+
numbers.some((n) => n > 10); // false
28+
numbers.sort((a, b) => b - a); // [5, 4, 3, 2, 1]
29+
numbers.reverse(); // [5, 4, 3, 2, 1]
30+
numbers.slice(0, 2); // [1, 2]
31+
numbers.splice(0, 2); // [1, 2]
32+
numbers.pop(); // [1, 2, 3, 4]
33+
numbers.push(6); // [1, 2, 3, 4, 6]
34+
numbers.includes(3); // true
35+
36+
////////////////////////////////
37+
// object methods
38+
const person = {
39+
name: "Alice",
40+
age: 30,
41+
greet: function () {
42+
console.log(`Hello, my name is ${this.name}!`);
43+
},
44+
};
45+
46+
person.greet(); // Hello, my name is Alice!
47+
48+
////////////////////////////////
49+
// destructuring
50+
const { name, age } = person;
51+
console.log(name); // Alice
52+
console.log(age); // 30
53+
54+
////////////////////////////////
55+
// array destructuring
56+
const [first, second, ...rest] = numbers;
57+
console.log(first); // 1
58+
console.log(second); // 2
59+
console.log(rest); // [3, 4, 5]
60+
61+
////////////////////////////////
62+
// default parameters
63+
function greet(name = "World") {
64+
console.log(`Hello, ${name}!`);
65+
}
66+
greet(); // Hello, World!

filesystem.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const fs = require("fs");
2+
3+
const content = fs.readFileSync("./MyDirectory/hello.html");
4+
fs.writeFileSync("hello.html", "Hello from Node.js");
5+
fs.mkdirSync("MyDirectory");

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nodejs-course",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

pages/about.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>about ruppin</title>
8+
</head>
9+
<body>
10+
<h1>About us</h1>
11+
</body>
12+
</html>

pages/contact.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Hello ruppin</title>
8+
</head>
9+
<body>
10+
<h1>Contact us</h1>
11+
</body>
12+
</html>

pages/hello.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Hello ruppin</title>
8+
</head>
9+
<body>
10+
<h1>hello ruppin server</h1>
11+
</body>
12+
</html>

routing.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// node js server with routing
2+
const http = require("http");
3+
const fs = require("fs");
4+
5+
const pages = "pages";
6+
7+
http
8+
.createServer((req, res) => {
9+
if (req.method === "GET") {
10+
if (req.url === "/") {
11+
const content = fs.readFileSync(`./${pages}/hello.html`);
12+
res.writeHead(200, { "Content-Type": "text/html" });
13+
return res.end(content);
14+
}
15+
if (req.url === "/about") {
16+
const content = fs.readFileSync(`./${pages}/about.html`);
17+
res.writeHead(200, { "Content-Type": "text/html" });
18+
return res.end(content);
19+
}
20+
if (req.url === "/contact") {
21+
const content = fs.readFileSync(`./${pages}/contact.html`);
22+
res.writeHead(200, { "Content-Type": "text/html" });
23+
return res.end(content);
24+
}
25+
}
26+
if (req.method === "POST") {
27+
fs.writeFileSync("hello.html", "Hello from Node.js");
28+
res.writeHead(200, { "Content-Type": "text/html" });
29+
return res.end("File saved");
30+
}
31+
})
32+
.listen(9999, () => {
33+
console.log("Server running at port 9999");
34+
});

server.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const http = require("http");
2+
3+
http
4+
.createServer((req, res) => {
5+
res.writeHead(200, { "Content-Type": "text/html" });
6+
res.end("Hello Ruppin!");
7+
})
8+
.listen(9999, () => {
9+
console.log("Server running at port 9999");
10+
});

0 commit comments

Comments
 (0)