This commit is contained in:
@@ -221,7 +221,7 @@ Abschlussquiz - JS Grundlagen
|
|||||||
|
|
||||||
**Übungen:**
|
**Übungen:**
|
||||||
|
|
||||||
Übung 09 - 10
|
Übung 09 - 11
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -230,8 +230,6 @@ Abschlussquiz - JS Grundlagen
|
|||||||
**Inhalt:**
|
**Inhalt:**
|
||||||
|
|
||||||
- Wiederholung der Inhalte
|
- Wiederholung der Inhalte
|
||||||
- commonjs vs esm
|
|
||||||
- async await
|
|
||||||
- Promise.all()
|
- Promise.all()
|
||||||
- **Exkurs: Switch Case Abfragen**
|
- **Exkurs: Switch Case Abfragen**
|
||||||
- **Exkurs: Statische Webseite mit Sass und HTML**
|
- **Exkurs: Statische Webseite mit Sass und HTML**
|
||||||
|
|||||||
11
02_advanced/faq/interval-funktionreferenz.js
Normal file
11
02_advanced/faq/interval-funktionreferenz.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const sayHello = () => {
|
||||||
|
console.log('Say hello');
|
||||||
|
};
|
||||||
|
|
||||||
|
const iv = setInterval(sayHello, 500);
|
||||||
|
|
||||||
|
const double = (n, i) => {
|
||||||
|
return n * 2 + i;
|
||||||
|
};
|
||||||
|
|
||||||
|
const numbers = [1, '2', 3].map(double);
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
// fs = FileSystem Modul aus der Node Standardbib
|
// fs = FileSystem Modul aus der Node Standardbib
|
||||||
const fs = require('fs'); // commonjs - Node Schreibweise
|
// const fs = require('fs'); // commonjs - Node Schreibweise
|
||||||
|
// const chalk = require('chalk');
|
||||||
|
import fs from 'fs'; // module - ESM Schreibweise
|
||||||
|
import chalk from 'chalk';
|
||||||
|
|
||||||
// Funktion mir einem asynchronen Prozess
|
// Funktion mir einem asynchronen Prozess
|
||||||
const getContentBy = (path) => {
|
const getContentBy = (path) => {
|
||||||
@@ -16,13 +19,13 @@ const getContentBy = (path) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funktionsaufruf einer Funktion mit asynchronem Prozess
|
// Funktionsaufruf einer Funktion mit asynchronen Prozess
|
||||||
getContentBy('data/productss.csv')
|
getContentBy('data/products.csv')
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log(data);
|
console.log(chalk.yellow(data));
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(chalk.red(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('weiter im code...');
|
console.log('weiter im code...');
|
||||||
|
|||||||
28
02_advanced/unterricht/tag14/01_promise-and-readfile/package-lock.json
generated
Normal file
28
02_advanced/unterricht/tag14/01_promise-and-readfile/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "01_promise-and-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "01_promise-and-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "5.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
|
||||||
|
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,13 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "",
|
"author": "",
|
||||||
"type": "commonjs",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": []
|
"keywords": [],
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// commonjs - Schreibweise mit "require"
|
||||||
|
const fs = require('node:fs'); // "fs" ist ein Modul aus der Node Standardbib und kann mit Prefix "node:" hervorgehoben werden
|
||||||
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
const getFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
// console.error(err);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf von Funktion mit async process
|
||||||
|
getFileBy('package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(chalk.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(chalk.red(err));
|
||||||
|
});
|
||||||
86
02_advanced/unterricht/tag14/02_commonjs-vs-esm/commonjs/package-lock.json
generated
Normal file
86
02_advanced/unterricht/tag14/02_commonjs-vs-esm/commonjs/package-lock.json
generated
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^4.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ansi-styles": {
|
||||||
|
"version": "4.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/has-flag": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/supports-color": {
|
||||||
|
"version": "7.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||||
|
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "commonjs",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^4.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// esm - Schreibweise mit "import"
|
||||||
|
import fs from 'node:fs'; // "fs" ist ein Modul aus der Node Standardbib und kann mit Prefix "node:" hervorgehoben werden
|
||||||
|
import chalk from 'chalk';
|
||||||
|
|
||||||
|
const getFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
// console.error(err);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf von Funktion mit async process
|
||||||
|
getFileBy('package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(chalk.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(chalk.red(err));
|
||||||
|
});
|
||||||
28
02_advanced/unterricht/tag14/02_commonjs-vs-esm/module/package-lock.json
generated
Normal file
28
02_advanced/unterricht/tag14/02_commonjs-vs-esm/module/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "5.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
|
||||||
|
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
40
02_advanced/unterricht/tag14/03_fs-promises/index.js
Normal file
40
02_advanced/unterricht/tag14/03_fs-promises/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// esm - Schreibweise mit "import"
|
||||||
|
import fs from 'node:fs'; // "fs" ist ein Modul aus der Node Standardbib und kann mit Prefix "node:" hervorgehoben werden
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
const getFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
// console.error(err);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPromisesFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
// Unterobjekt "promises" von fs besitzt Ummantelung von Promise-Objekt und Verarbeitung der Callback-Funktion
|
||||||
|
return fs.promises.readFile(path, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf von Funktion mit async process
|
||||||
|
getFileBy('package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(color.red(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
getPromisesFileBy('package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.green(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(color.magenta(err));
|
||||||
|
});
|
||||||
28
02_advanced/unterricht/tag14/03_fs-promises/package-lock.json
generated
Normal file
28
02_advanced/unterricht/tag14/03_fs-promises/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "5.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
|
||||||
|
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
02_advanced/unterricht/tag14/03_fs-promises/package.json
Normal file
16
02_advanced/unterricht/tag14/03_fs-promises/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "03_fs-promises",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
35
02_advanced/unterricht/tag14/04_async-await/index.js
Normal file
35
02_advanced/unterricht/tag14/04_async-await/index.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// esm - Schreibweise mit "import"
|
||||||
|
import fs from 'node:fs'; // "fs" ist ein Modul aus der Node Standardbib und kann mit Prefix "node:" hervorgehoben werden
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
// async ... await
|
||||||
|
const getFileBy = async (path, encoding = 'utf-8') => {
|
||||||
|
try {
|
||||||
|
const result = await fs.promises.readFile(path, encoding);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPromiseFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(path, encoding, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
getFileBy('package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.green(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(color.magenta(err));
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
console.log(color.yellow('process finished'));
|
||||||
|
});
|
||||||
28
02_advanced/unterricht/tag14/04_async-await/package-lock.json
generated
Normal file
28
02_advanced/unterricht/tag14/04_async-await/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "5.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
|
||||||
|
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
02_advanced/unterricht/tag14/04_async-await/package.json
Normal file
16
02_advanced/unterricht/tag14/04_async-await/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "04_async-await",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Ich bin file01
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Ich bin file02
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Ich bin file03
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Ich bin file04
|
||||||
28
02_advanced/unterricht/tag14/05_promise-all/index.js
Normal file
28
02_advanced/unterricht/tag14/05_promise-all/index.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
const getFileBy = (path, encoding = 'utf-8') => {
|
||||||
|
return fs.promises.readFile(path, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
// getFileBy('data/file01.txt')
|
||||||
|
// .then((data) => {
|
||||||
|
// console.log(color.green(data));
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// console.log(color.red(err));
|
||||||
|
// });
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
getFileBy('data/file01.txt'),
|
||||||
|
getFileBy('data/file02.txt'),
|
||||||
|
// getFileBy('data/404'),
|
||||||
|
getFileBy('data/file03.txt'),
|
||||||
|
getFileBy('data/file04.txt'),
|
||||||
|
])
|
||||||
|
.then((data) => {
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
28
02_advanced/unterricht/tag14/05_promise-all/package-lock.json
generated
Normal file
28
02_advanced/unterricht/tag14/05_promise-all/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-all",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "05_promise-all",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "5.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
|
||||||
|
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
02_advanced/unterricht/tag14/05_promise-all/package.json
Normal file
16
02_advanced/unterricht/tag14/05_promise-all/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-all",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"keywords": [],
|
||||||
|
"license": "ISC",
|
||||||
|
"author": "",
|
||||||
|
"type": "module",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Ich bin eine Datei!
|
||||||
16
02_advanced/unterricht/tag15/01_util-promisify/index.js
Normal file
16
02_advanced/unterricht/tag15/01_util-promisify/index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// const fs = require('fs');
|
||||||
|
// const util = require('util');
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import util from 'node:util';
|
||||||
|
|
||||||
|
// util.promisify fängt das letzte Argument als Callback-Funktion ab und ummantel die Funktion mit einem Promise-Objekt.
|
||||||
|
// Das ummantelte Promise-Objekt wird zusätzlich von einer weiteren Funktion mit den Argumenten ummantelt.
|
||||||
|
|
||||||
|
// https://javascript.info/promisify
|
||||||
|
// https://medium.com/trabe/understanding-nodes-promisify-and-callbackify-d2b04efde0e0
|
||||||
|
|
||||||
|
const getFileContent = util.promisify(fs.readFile);
|
||||||
|
|
||||||
|
getFileContent('data/file.txt', 'utf8')
|
||||||
|
.then((data) => console.log(data))
|
||||||
|
.catch((err) => console.error(`Something went wrong: ${err}`));
|
||||||
13
02_advanced/unterricht/tag15/01_util-promisify/package.json
Normal file
13
02_advanced/unterricht/tag15/01_util-promisify/package.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "01_util-promisify",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user