This commit is contained in:
@@ -0,0 +1 @@
|
||||
Ich bin file 01
|
||||
@@ -0,0 +1 @@
|
||||
Ich bin file 02
|
||||
@@ -0,0 +1 @@
|
||||
Ich bin file 03
|
||||
@@ -0,0 +1 @@
|
||||
Ich bin file 04
|
||||
@@ -0,0 +1 @@
|
||||
Ich bin file 05
|
||||
@@ -0,0 +1 @@
|
||||
Ich bin file 06
|
||||
29
02_advanced/uebungen/u12_mehrere-dateien-auslesen/index.js
Normal file
29
02_advanced/uebungen/u12_mehrere-dateien-auslesen/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// const fs = require('node:fs'); // commonjs
|
||||
import fs from 'node:fs'; // esm - module Schreibweise
|
||||
|
||||
const getFileBy = (path, encoding = 'utf-8') => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// async process
|
||||
fs.readFile(path, encoding, (error, data) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Promise.all([
|
||||
getFileBy('data/file01.txt'),
|
||||
getFileBy('data/file02.txt'),
|
||||
getFileBy('data/file03.txt'),
|
||||
getFileBy('data/file04.txt'),
|
||||
getFileBy('data/file05.txt'),
|
||||
getFileBy('data/file06.txt'),
|
||||
])
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "u12_mehrere-dateien-auslesen",
|
||||
"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