I used 3 different File System APIs in Node.js

  Рет қаралды 110,045

Beyond Fireship

Beyond Fireship

Жыл бұрын

Learn 3 different ways to read or write files in Node.js and their tradeoffs.
#nodejs #javascript #tutorial
Node FS nodejs.org/api/fs.html

Пікірлер: 120
@Krikit1337
@Krikit1337 Жыл бұрын
Shouldn't that be await readdir for the promises API?
@beyondfireship
@beyondfireship Жыл бұрын
ah yes, good call
@tacticalassaultanteater9678
@tacticalassaultanteater9678 Жыл бұрын
This is also by far the most common bug with promises, and one Typescript doesn't catch by default. There's an ESLint rule to ban unhandled promise rejections that also catches unawaited promises
@ivanfaye3041
@ivanfaye3041 Жыл бұрын
@@tacticalassaultanteater9678 ?? When I use typescript it does catches promises that have not been waited
@arthurcoser
@arthurcoser Жыл бұрын
@@ivanfaye3041 only if you're using the result of the promise to do something, if you're just running them and doing something else it can't tell if it's intended or not
@poolkrooni
@poolkrooni Жыл бұрын
@@tacticalassaultanteater9678 mate could you share the rule you're talking about?
@nagarajansubramani
@nagarajansubramani Жыл бұрын
I love how in your videos you setup the code as a series of Undo operations so as you continually press Ctrl+Z the code lines magically appear pasted on screen as you speak along.
@ewanmunro7580
@ewanmunro7580 Жыл бұрын
I think a more code focused channel makes a lot of sense. Combining your iconic voice and concise (and fun) writing with a traditional education kind of feel.
@parlor3115
@parlor3115 Жыл бұрын
Get the best of both worlds ayy?
@evols7028
@evols7028 Жыл бұрын
I had not used callbacks for a long time, this video revived my callback PTSD. Async/await truly is a marvelous thing
@blueguy5588
@blueguy5588 Жыл бұрын
This is a great channel idea. I agree with others; at a certain point, it becomes easiest to understand how a piece of software works simply by looking at the code, so it makes sense to have a channel where code is central.
@yungifez
@yungifez Жыл бұрын
This channel feels premium
@guilhermealveslopes
@guilhermealveslopes Жыл бұрын
I love this channel Jeff, I subscribed with Bell icon, cause me, and buch of other people, highly want to see tons upon tons of very specific non-introductory pieces like this. And then maybe in the end we could build a guides website for all of javascript with just videos from this channel.
@RaymondovanDijk
@RaymondovanDijk Жыл бұрын
Going fast! 2 vids on the same day😱
@abdullahsoomro6238
@abdullahsoomro6238 Жыл бұрын
Lovely videos. Keep uploading short and very informative videos. And thank you for creating such an amazing content.
@erminpajazetovic9506
@erminpajazetovic9506 Жыл бұрын
The folder name💀💀
@alloycipher4528
@alloycipher4528 Жыл бұрын
i respect your work ethic
@e-jarod4110
@e-jarod4110 Жыл бұрын
A tutorial about oauth in nestjs / node.js (without existing passport lib) will be awesome Some OAuth services have not their own passport plugin
@salman0ansari
@salman0ansari Жыл бұрын
we need more content like this
@ritwan3952
@ritwan3952 10 ай бұрын
THIS IS AMAZING
@user-sn8hm4bm3j
@user-sn8hm4bm3j Жыл бұрын
Well done
@debjanisarkar9756
@debjanisarkar9756 Жыл бұрын
Thanks a lot!!
@neilvasu
@neilvasu Жыл бұрын
yesss this is what we need, in the weeds snippets
@lolidkstudio
@lolidkstudio Жыл бұрын
fireship new channel moment
@thmsrttg
@thmsrttg Жыл бұрын
love that directory name 😆
@Infinitay
@Infinitay Жыл бұрын
I would love if this second channel hosts various comparisons and benchmarks between different libraries, and even libraries in other languages.
@allentom97
@allentom97 Жыл бұрын
Seems out of scope for this channel? Seeing as it is focusing on specific tutorials
@yairopro
@yairopro Жыл бұрын
Graph-fs does a great job
@re.liable
@re.liable Жыл бұрын
I'd be interested in a video about js/mjs/cjs extensions, and the `node:` prefix for built-in modules
@vicjajsalu2
@vicjajsalu2 Жыл бұрын
New firship channel!
@zozodejante8350
@zozodejante8350 Жыл бұрын
Your upload schedule on this channel is blazingly fast bro
@alexradu1921
@alexradu1921 Жыл бұрын
sometimes I wonder when does he have time to go outside, eat, wash, clean, sleep... he's just making one high quality video after another which is like crazy
@Mufti199
@Mufti199 Жыл бұрын
A server side app that deletes things from my "notporn" folder? Great product-market fit!
@sweatypotato248
@sweatypotato248 Жыл бұрын
what? this channel exist I didnt know until now
@fizipcfx
@fizipcfx Жыл бұрын
this videos are awesome man
@tekno47
@tekno47 Жыл бұрын
fs-extra is the goat
@anthonybyansi4255
@anthonybyansi4255 Жыл бұрын
Even though you create 100 fireship channels, I will definitely npm sub fireship
@mehboobdev
@mehboobdev Жыл бұрын
Folder name was awesome 😎, lol
@CarlenWhite
@CarlenWhite Жыл бұрын
It isn't running a separate thread when it comes to callbacks/promises, it's the event loop. AFAIK you're adding something to the event loop, your function yields, the loop polls for status, and runs the associated callback(s) if needed plus anything else. If you've worked with an async runtime in Rust, you might know what's going on here.
@SamualN
@SamualN Жыл бұрын
he means the request to go get the directory and wait for the os to respond etc is off the main thread
@ed_iz_ed
@ed_iz_ed Жыл бұрын
in a way is a separate thread, io can go on while the code executes, but callbacks will execute on the same single thread
@okie9025
@okie9025 Жыл бұрын
Actually Node _does_ launch a separate thread for IO operations, but this is the only case where that happens (except WebWorkers but that's browser-only)
@phatakom
@phatakom Жыл бұрын
async-await syntax is just love
@isaacqadri
@isaacqadri Жыл бұрын
Hello, i love fireship.
@AbhishekKumar-qx9wq
@AbhishekKumar-qx9wq Жыл бұрын
Directory name sus 🙂
@supercellodude
@supercellodude Жыл бұрын
If I was a smug scheme or haskell weenie, I'd drone on about "oh javascript has finally caught on with continuation programming". However, waiting for standards bodies to try and "zip together" divergent implementations' feature sets is very familiar between ecmascript and the RnRS.
@kartikchauhan2778
@kartikchauhan2778 Жыл бұрын
Please make a video on django backend development Thanks
@Ai4698
@Ai4698 Жыл бұрын
Currently doing spring security and cors is beating me up so bad. I'm using react as my front end
@wlockuz4467
@wlockuz4467 Жыл бұрын
Should've mentioned, that to catch errors with fs/promises its as simple as wrapping all your calls inside a try/catch, much better than declaring 10 different .catch() callbacks then losing your mind.
@shoucs2
@shoucs2 Жыл бұрын
Great Video, but to complete your KZbin career you will now we need a "Afar Fireship" channel too.
@LetrixAR
@LetrixAR Жыл бұрын
fs-extra is great
@cloud244
@cloud244 Жыл бұрын
Nice! I often use the first method which can get ugly quite quickly. I will give the fs/promises a try!
@cauhxmilloy7670
@cauhxmilloy7670 Жыл бұрын
One topic that I wish I saw talked about more on some edu vids, nudge nudge, is that callback hell often gets blamed on the callback API. Instead, IMO, it should be blamed on the over abundant use of anonymous inline functions / lambdas. Using normal named functions as callbacks allows for callback APIs to be used with no risk of callback hell. You do miss out on variable captures, but that is something that is often relied on out of laziness and can cause it's own bugs. I like callback APIs as they are often much lighter weight and easier to debug than other OOP counterparts, like promises.
@LC-hd5dc
@LC-hd5dc Жыл бұрын
then you're creating a new kind of code smell by splitting out one-off functions really the only viable option for async handling in js is promises
@pepkin88
@pepkin88 Жыл бұрын
Callback hell is not about indentations or anonymous functions. It's about ensuring that no callback will throw, because each uncaught exception will crash the app, and it's by design. The example in this video is unfortunate, because you cannot handle exceptions that way using Node's callback api.
@benelhadjdjellouloussama4286
@benelhadjdjellouloussama4286 Жыл бұрын
Yoo Bro, can you please show us ways how to handle images in DB in Nodejs
@shaftymaze
@shaftymaze Жыл бұрын
Deno’s fresh lemon drop animation please 🎉❤
@SivicIsntFat
@SivicIsntFat Жыл бұрын
Isn’t it running in the same thread but on the eventloop?
@sintaulsiam
@sintaulsiam Жыл бұрын
Just hoped in
@upendranayak6344
@upendranayak6344 Жыл бұрын
Man the software scares it's terrifying
@thestreamer1481
@thestreamer1481 Жыл бұрын
You man, do a video of intro to the channel
@emmanuelotobo7944
@emmanuelotobo7944 Жыл бұрын
Doesn't using await before the Promise.all() pause the execution of the code until all the files have been removed?
@petrustefanescu5842
@petrustefanescu5842 Жыл бұрын
Yes, but file removals are done independent of each other. Awaiting Promise.all is like a barrier that only lets flow go further only if all operations are done
@seannewell397
@seannewell397 Жыл бұрын
I wish someone would just use separate functions for the callback api; it's my first thought when using them.
@elysiapog3402
@elysiapog3402 Жыл бұрын
yay
@_vicary
@_vicary Жыл бұрын
the callbacks totally reminded me when Isaacs pushed back fs/promises for so long, this guy should be the most hated dirtbag in the JavaScript history.
@joostkoch7229
@joostkoch7229 Жыл бұрын
17k gang
@JITSoftware
@JITSoftware Жыл бұрын
Cool video, but I'm torn by that syntax error at 0:53
@pepkin88
@pepkin88 Жыл бұрын
I don't see any syntax errors there (maybe only misaligned indents). But I do see throwing exceptions from a callback, and that is a big no-no.
@pepkin88
@pepkin88 Жыл бұрын
0:53 Regarding callbacks, you do not want to throw errors like that. If you do that, there's no way to catch them, other that process.on('uncaughtException', ...), which is a catch-all for all exceptions and should be proceeded by exiting the process. Callback hell is not about indentations. It's about ensuring that there is no callback that will just crash the app because of an uncaught exception. But we live in the future now and promises are the way to go. P.S.: There is one more way to access the file system, and that is through streams, like fs.createReadStream(...).
@magnusmarkling
@magnusmarkling Жыл бұрын
"one of the most common operations in server-side code is to read and write from the filesystem" I honestly haven't done that in the last ten years or so.
@cphoover11
@cphoover11 Жыл бұрын
Callbacks are just there to support legacy applications devs should favor promises IMO
@darkwoodmovies
@darkwoodmovies Жыл бұрын
Adding more dependencies to a Node project? I would never...
@clockwise9179
@clockwise9179 Жыл бұрын
Please enable save video :((
@cool_scatter
@cool_scatter Жыл бұрын
Seems like promises are the clear winner here
@clashclan4739
@clashclan4739 Жыл бұрын
Need angular related stuffs
@EthioWonder
@EthioWonder Жыл бұрын
What the hech is the directory name
@Username5H0
@Username5H0 Жыл бұрын
No one gonna mention that directory name though?
@Manish___Choudhary
@Manish___Choudhary Жыл бұрын
Is there any js package that can get the logo of the inserted website URL?
@SamualN
@SamualN Жыл бұрын
do you mean the favicon? if so you don't need a package to do that just request and download the favicon
@ericktorres9791
@ericktorres9791 Жыл бұрын
You don't need to do that. Just use the fetch API to request the HTML of the website and search for the favicon which is the tag. Something like this await fetch('www.youtube.com').then(response => response.text()).match(//g) will get you all of the different favicons. Best of luck!
@gangatharanr1995
@gangatharanr1995 Жыл бұрын
Some favicons are directly hardcoded in base64 format. You might have to factor that too
@bugdeveloper
@bugdeveloper Жыл бұрын
O my callback hell
@ayank007
@ayank007 Жыл бұрын
Is there any Noob Fireship channel I'm missing?
@the-old-channel
@the-old-channel Жыл бұрын
I miss the background music
@shepardpower
@shepardpower Жыл бұрын
Bruh that thumbnail is cursed lol
@pauljohnsonbringbackdislik1469
@pauljohnsonbringbackdislik1469 Жыл бұрын
I wish fs/promises include "exists()". It's a bummer to be forced to use "access(...).then(() => true, () => false)"
@turolretar
@turolretar Жыл бұрын
Are u on tiktok?
@baxiry.
@baxiry. Жыл бұрын
All roads lead to golang
@akam9919
@akam9919 Жыл бұрын
There's definitely not porn in that folder... foo just has a list of sites... bar has ids...
@ugokrollak2315
@ugokrollak2315 Жыл бұрын
Mmmm
@marian7429
@marian7429 Жыл бұрын
sus directory name
@AmodeusR
@AmodeusR 10 ай бұрын
To be honest, I rather learn python and do it with it than trying to tinker with this.
@Henry-mc5yq
@Henry-mc5yq Жыл бұрын
No caffeine going good?
@atesztoth
@atesztoth Жыл бұрын
I like your videos very much, but I noticed you often confuse something about the Promise.all API. You usually say it’s running promises in parallel. But since the Node runtime is single threaded, it cannot do paralellism but runs your promises concurrently. There is a big difference. True paralellism is achievable using Node, but you must utilize worker threads or child processes to do so. Cheers!
@bigmistqke
@bigmistqke Жыл бұрын
Could u elaborate what the difference is?
@atesztoth
@atesztoth Жыл бұрын
​@@bigmistqke The point is this: www.baeldung.com/wp-content/uploads/sites/4/2022/01/vs-1024x462-1.png The easiest to understand if you imagine you're carrying two bags from point A to B. In case of concurrency you are going to carry bag "a" a bit, then bag "b" a bit and you do it repeatedly until you're ready. Carrying concurrently means you're grab the two bags at the same time and bring them both to point B.
@arjix8738
@arjix8738 Жыл бұрын
so the title is misleading and you used the same API in three different ways
@tjgdddfcn
@tjgdddfcn Жыл бұрын
just delete the directory and make a new one with the same name
@mingsumsze6026
@mingsumsze6026 Жыл бұрын
50/50 that directory is for porn
@SpeckyYT
@SpeckyYT Жыл бұрын
This was a poorly made video being honest. 0:12 why did you name the folder like that 0:46 how did you mess up the indentation? 0:55 errors in callbacks aren't thrown like that, since there is no way to catch them except by listening to the process' uncaught exceptions event 1:18 if you did "if (err) throw err" in the callbacks example, why aren't you try/catching it in the sync example? 1:39 no "await"? did you even test your examples before showing them? 1:54 no ".catch()"? what's the point of comparing different methods of doimg the same things while not managing everything the same way? Unsubscribed.
@bigmistqke
@bigmistqke Жыл бұрын
Ye agree. the examples were poorly written
@ayecaptainjack6930
@ayecaptainjack6930 Жыл бұрын
why are you always talking about “main thread” or “thread-pool” when talking about asynchronous programming? JS is single threaded, it doesn’t make sense to talkt about anything thread related. (You did the same thing in your async-await video)
@jww0007
@jww0007 Жыл бұрын
choice of filepath name wasn't tasteful I must say
@jww0007
@jww0007 Жыл бұрын
🤦🏽‍♂️
@SirDamatoIII
@SirDamatoIII Жыл бұрын
But it was funny
@thunderskull258
@thunderskull258 Жыл бұрын
Isn't python better
@rahulr9539
@rahulr9539 Жыл бұрын
do you even know how to use async/await in python?
@rahulr9539
@rahulr9539 Жыл бұрын
Warning: while using Promise.all() with recursive calls, I once tried to hash files in a directory recursively. And all 4500+ files were processed at the same time and the system froze. Another problem with Promise.all() is it throws error if any of the task fails. use Promise.allSettled(), but still ot doesn't solve the first problem, for that you will have to use some sort of buffered queue
@NamasteProgramming
@NamasteProgramming Жыл бұрын
Wow, I used to use utli.promisfy to make callback into promise
@shimadabr
@shimadabr Жыл бұрын
Meanwhile in 1969 (Unix): rm /path/to/dir/*
I tried 8 different Postgres ORMs
9:46
Beyond Fireship
Рет қаралды 400 М.
React VS Svelte...10 Examples
8:35
Beyond Fireship
Рет қаралды 541 М.
Это реально работает?!
00:33
БРУНО
Рет қаралды 4 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 15 МЛН
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН
Make Money from your API Tutorial
13:10
Fireship
Рет қаралды 871 М.
File Handling in NodeJS
18:17
Piyush Garg
Рет қаралды 91 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 272 М.
How GitHub Actions 10x my productivity
8:18
Beyond Fireship
Рет қаралды 403 М.
Stop, Intel’s Already Dead! - AMD Ryzen 9600X & 9700X Review
13:47
Linus Tech Tips
Рет қаралды 1,1 МЛН
How I deploy serverless containers for free
6:33
Beyond Fireship
Рет қаралды 474 М.
All you need to know about "child_process" in Node.js
12:38
Software Developer Diaries
Рет қаралды 5 М.
Beyond Surreal? A closer look at NewSQL Relational Data
7:52
Beyond Fireship
Рет қаралды 199 М.
Time is Relative, even in JavaScript
1:17
Beyond Fireship
Рет қаралды 98 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 638 М.