diff --git a/02_advanced/unterricht/tag13/07_fs-promises/index.js b/02_advanced/unterricht/tag13/07_fs-promises/index.js index bcd2828..64b39e3 100644 --- a/02_advanced/unterricht/tag13/07_fs-promises/index.js +++ b/02_advanced/unterricht/tag13/07_fs-promises/index.js @@ -1,11 +1,9 @@ // 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') => { +const getFileBy = (path = '', encoding = 'utf-8') => { return new Promise((resolve, reject) => { // async process fs.readFile(path, encoding, (error, data) => { @@ -20,8 +18,15 @@ const getContentBy = (path = '', encoding = 'utf-8') => { }); }; +const getPromisesFileBy = (path = '', encoding = 'utf-8') => { + // Unterobjekt "promises" von fs besitzt Ummantelung von Promise-Objekt und die Verarbeitung der Callback-Funktion + + // async process + return fs.promises.readFile(path, encoding); +}; + // Funktionsaufruf einer Funktion mit asynchronem Prozess -getContentBy('./data/products.csv') +getPromisesFileBy('./data/products.csv') .then((data) => { console.log(color.yellow(data)); }) diff --git a/02_advanced/unterricht/tag13/07_fs-promises/package.json b/02_advanced/unterricht/tag13/07_fs-promises/package.json index 09556ff..50af2e1 100644 --- a/02_advanced/unterricht/tag13/07_fs-promises/package.json +++ b/02_advanced/unterricht/tag13/07_fs-promises/package.json @@ -1,5 +1,5 @@ { - "name": "05_promise-readfile", + "name": "07_fs-promises", "version": "1.0.0", "description": "", "main": "index.js",