All right.
So now we are actually able to get the image URLs for all these beautiful posters for the different
movies.
And so now we just need to be able to save the file or save the image to our disk.
And I made a folder in here that is called Posters where we will be saving the images to.
So let's make another function.
We call it save poster image to disk.
We pass in a movie object in here and in here we are going to use the old type of request that is not
using the regular promises.
So I'm going to call this regular request.
That's just my fancy name for it.
You can call it whatever you want.
And we require the request here.
So regular request, I call it.
And let me show you what we do.
We say regular request.
Get.
Movie and we say poster image URL, and then we use pipe and we also need to import FS for file stream
to save the file.
So const FS require fs.
And say FS create write stream.
And in here we put the path or the URL, the file name to the file we are going to save.
So I think we will save it as in posters and we are going to use the rank of the movie as the file name
and end it with PNG.
So I'm using the rank now because some of the titles have characters that's not so suitable for file
names.
So for simplicity's sake, for simplicity's sake, I'm using rank instead.
Okay.
And that should be it.
Now, instead of going through all of the movies to get their poster image URL, you could do that.
But just so we can see the results as early as possible, I'm going to call the function inside the
script poster image URL function instead.
So scrape, poster image or say poster image to disk and we pass in the movie object in here.
Okay, So let's see if it runs.
If it saves the images to the disk.
So it's starting up the nightmare browser here and it's saying no such file or directory.
It's because I called it poster instead of posters.
So let's just correct that to posters and we try and run it again.
And now, since it can find the directory, it should be able to save the file.
Okay, so there we go.
And we see the files is being saved here.
Okay, So number one, we have Bohemian Rhapsody over here and so on and so on.
So everything is working just fine now.