Okay, Now let's create our famous Index.js file.
Index.js.
And then we are going to import request.
So a quiet quest promise.
And we are also going to create a method, just call it async function main.
And.
Then we are going to use a function or I'm sorry, options object.
So we define an object here called options and we say the method is post.
That's what we are using to log in.
And then we put in a Uri and the Uri is the URL we got from when we are looking inside of this Firefox
Facebook page where we looked at the action attribute inside of the form.
And that's the URL we have here.
Remember, it's Uri, they call it here, not URL.
And then we have the form data, we call it form, and we use a pass in the email.
And I'm going to make another file here called Credentials Dot, Email and Pass.
I also say credentials dot pass.
However, if you want to do this, you can just write your email out in a string like my email.
Um, email.com.
And I'm just doing this because I don't want to sit and edit my email and pass out in the video.
So I'm going to make another file called Credentials and import it.
And let's see.
So
here I'm going to type in my email.
And my pass.
And of course, you don't have to do this section.
I'm just showing you what I'm doing.
Exactly.
So you understand what is going on here.
So.
The name Port The file.
And then I can use it down here so I don't have to edit out my email all the time.
And then we need to set that.
Actually, I will not get to that yet.
We will just try and complete the, um, the request now.
So hold on a moment while I put in my actual credentials in the the the file here.
Okay, so now I put in my actual Facebook email and password in the other file we defined here.
And now we're going to try and actually complete this request we got here.
So we say const result await request and then we pass in the options object that we defined here, which
says it's a post and so on.
And then we are going to.
See what we get.
Actually, I'm also going to write a catch clause here.
Console error.
Error.
And I will write out error here.
So I know it's an error, not just a regular result and.
Okay, so let's try and see what happens now.
We're making a post request.
We're doing it in the same way with the form URL encoded as we did inside of Postman, and we're using
the post method to this URL we got from the Firefox page.
Now let's try and see what happens when we try and run it.
And nothing happens because I'm not running the method.
So let's type main down here in the global scope and run it again.
So I get this huge object here, which is the response.
And I get an error.
And the reason we are getting an error is because it's returning a status code.
302.
And that's basically a redirect.
Now inside of Postman, Postman is automatically redirecting the request so it gets to the right place.
However, request doesn't do that automatically.
It doesn't redirect the request automatically.
Let me try and set a breakpoint here so you can see the how the response looks like.
So I'm going into debugging in Visual Studio code and we will try and see how it looks like.
So here we go.
We are going now inside of the catch clause here.
And if we go inside of error, we can see there's a status code 302, which is not really an error.
It's more of a redirect, but request by default treats this as an error.
But we can do a little option inside of it to make sure that we handle it the right way, which I will
do in the next lecture.