This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
name, category, price
|
||||||
|
Klingon Letter Opener, Office Warfare, 19.99
|
||||||
|
Backpack of Holding, Travel, 29.99
|
||||||
|
Tardis Alarmclock, Merchandise, 15.99
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
// fs = FileSystem Modul aus der Node Standardbib (core)
|
||||||
|
// const fs = require('node:fs'); // commonjs Schreibweise
|
||||||
|
// const color = require('chalk');
|
||||||
|
import fs from 'node:fs'; // module - ESM Schreibweise
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
// Funktion mit einem asynchronen Prozess
|
||||||
|
const getContentBy = (path = '', encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (error, data) => {
|
||||||
|
if (error) {
|
||||||
|
// console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf einer Funktion mit asynchronem Prozess
|
||||||
|
getContentBy('./data/products.csv')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(color.red(err));
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "6.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
|
||||||
|
"integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// commonjs Schreibweise
|
||||||
|
const fs = require('node:fs'); // commonjs Schreibweise
|
||||||
|
const color = require('chalk');
|
||||||
|
|
||||||
|
// Funktion mit einem asynchronen Prozess
|
||||||
|
const getContentBy = (path = '', encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (error, data) => {
|
||||||
|
if (error) {
|
||||||
|
// console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf einer Funktion mit asynchronem Prozess
|
||||||
|
getContentBy('./package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(color.red(err));
|
||||||
|
});
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
{
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"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,14 @@
|
|||||||
|
{
|
||||||
|
"name": "commonjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"type": "commonjs",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^4.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// module Schreibweise
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
// Funktion mit einem asynchronen Prozess
|
||||||
|
const getContentBy = (path = '', encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (error, data) => {
|
||||||
|
if (error) {
|
||||||
|
// console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf einer Funktion mit asynchronem Prozess
|
||||||
|
getContentBy('./package.json')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(color.red(err));
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "6.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
|
||||||
|
"integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
name, category, price
|
||||||
|
Klingon Letter Opener, Office Warfare, 19.99
|
||||||
|
Backpack of Holding, Travel, 29.99
|
||||||
|
Tardis Alarmclock, Merchandise, 15.99
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
// fs = FileSystem Modul aus der Node Standardbib (core)
|
||||||
|
// const fs = require('node:fs'); // commonjs Schreibweise
|
||||||
|
// const color = require('chalk');
|
||||||
|
import fs from 'node:fs'; // module - ESM Schreibweise
|
||||||
|
import color from 'chalk';
|
||||||
|
|
||||||
|
// Funktion mit einem asynchronen Prozess
|
||||||
|
const getContentBy = (path = '', encoding = 'utf-8') => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// async process
|
||||||
|
fs.readFile(path, encoding, (error, data) => {
|
||||||
|
if (error) {
|
||||||
|
// console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funktionsaufruf einer Funktion mit asynchronem Prozess
|
||||||
|
getContentBy('./data/products.csv')
|
||||||
|
.then((data) => {
|
||||||
|
console.log(color.yellow(data));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(color.red(err));
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "6.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
|
||||||
|
"integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "05_promise-readfile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^6.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user