-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MJ - Day2 #3
base: master
Are you sure you want to change the base?
MJ - Day2 #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super rozwiązanie.
|
||
fs.writeFile('./data/zadanie01/sum.txt', sum, err => { | ||
let msg = err ? 'Błąd zapisu pliku' : 'Plik poprawnie zapisany'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Dodatkowo, można było użyć const
.
files.forEach(file => { | ||
console.log(`Nazwa pliku: ${file}`); | ||
let data = fs.readFileSync(`${path}${file}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Staramy się zawsze używać funkcji asynchronicznych - dlatego tylko takie poznaliśmy. Dzięki temu kiedy Node.js "nudzi się" odczytem pliku - mogą się dziać inne rzeczy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tak racja. Chciałem tym uzyskać odczyt pliku pod nazwą pliku bez rejestrowania eventu :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jasna sprawa :) Wygląda "prościej", ale właśnie nie korzysta z tej przewagi Node.
Natomiast taka ciekawostka, że używając Promise + async/await da się pisać kod który wygląda jak synchroniczny, a jest asynchroniczny ^^
if (err) return console.log('Błąd odczytu pliku'); | ||
|
||
let newData = [...data].map((elem, i) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Najlepszy sposób.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dziękuję :)
No description provided.