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.
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 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
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.
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.
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.
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.
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)
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
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.
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.
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.
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.
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(...).
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.
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
"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.
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.
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 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.
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)
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!
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
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.
Shouldn't that be await readdir for the promises API?
ah yes, good call
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
@@tacticalassaultanteater9678 ?? When I use typescript it does catches promises that have not been waited
@@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
@@tacticalassaultanteater9678 mate could you share the rule you're talking about?
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.
Get the best of both worlds ayy?
I had not used callbacks for a long time, this video revived my callback PTSD. Async/await truly is a marvelous thing
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.
This channel feels premium
Lovely videos. Keep uploading short and very informative videos. And thank you for creating such an amazing content.
Going fast! 2 vids on the same day😱
A tutorial about oauth in nestjs / node.js (without existing passport lib) will be awesome
Some OAuth services have not their own passport plugin
i respect your work ethic
Graph-fs does a great job
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.
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.
he means the request to go get the directory and wait for the os to respond etc is off the main thread
in a way is a separate thread, io can go on while the code executes, but callbacks will execute on the same single thread
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)
THIS IS AMAZING
we need more content like this
fireship new channel moment
I would love if this second channel hosts various comparisons and benchmarks between different libraries, and even libraries in other languages.
Seems out of scope for this channel?
Seeing as it is focusing on specific tutorials
A server side app that deletes things from my "notporn" folder? Great product-market fit!
I'd be interested in a video about js/mjs/cjs extensions, and the `node:` prefix for built-in modules
The folder name💀💀
Your upload schedule on this channel is blazingly fast bro
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
what? this channel exist I didnt know until now
love that directory name 😆
yesss this is what we need, in the weeds snippets
New firship channel!
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.
Great Video, but to complete your UA-cam career you will now we need a "Afar Fireship" channel too.
Even though you create 100 fireship channels, I will definitely npm sub fireship
Thanks a lot!!
Well done
Folder name was awesome 😎, lol
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.
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.
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
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.
async-await syntax is just love
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(...).
Yoo Bro, can you please show us ways how to handle images in DB in Nodejs
Man the software scares it's terrifying
Cool video, but I'm torn by that syntax error at 0:53
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.
fs-extra is the goat
Hello, i love fireship.
Please make a video on django backend development
Thanks
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.
Nice! I often use the first method which can get ugly quite quickly. I will give the fs/promises a try!
I wish someone would just use separate functions for the callback api; it's my first thought when using them.
Deno’s fresh lemon drop animation please 🎉❤
this videos are awesome man
Callbacks are just there to support legacy applications devs should favor promises IMO
fs-extra is great
You man, do a video of intro to the channel
Adding more dependencies to a Node project? I would never...
Directory name sus 🙂
Is there any Noob Fireship channel I'm missing?
Currently doing spring security and cors is beating me up so bad. I'm using react as my front end
Doesn't using await before the Promise.all() pause the execution of the code until all the files have been removed?
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
I wish fs/promises include "exists()". It's a bummer to be forced to use "access(...).then(() => true, () => false)"
Isn’t it running in the same thread but on the eventloop?
Seems like promises are the clear winner here
I miss the background music
Just hoped in
No one gonna mention that directory name though?
Are u on tiktok?
Please enable save video :((
"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.
17k gang
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.
Ye agree. the examples were poorly written
yay
What the hech is the directory name
Bruh that thumbnail is cursed lol
Need angular related stuffs
There's definitely not porn in that folder...
foo just has a list of sites...
bar has ids...
so the title is misleading and you used the same API in three different ways
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!
Could u elaborate what the difference is?
@@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.
All roads lead to golang
To be honest, I rather learn python and do it with it than trying to tinker with this.
No caffeine going good?
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)
O my callback hell
Is there any js package that can get the logo of the inserted website URL?
do you mean the favicon? if so you don't need a package to do that
just request and download the favicon
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!
Some favicons are directly hardcoded in base64 format. You might have to factor that too
just delete the directory and make a new one with the same name
sus directory name
choice of filepath name wasn't tasteful I must say
🤦🏽♂️
But it was funny
Mmmm
50/50 that directory is for porn
Isn't python better
do you even know how to use async/await in python?
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
Meanwhile in 1969 (Unix):
rm /path/to/dir/*
Wow, I used to use utli.promisfy to make callback into promise