Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics Handling Errors in Node The error event in Node

Crystal Vesely
Crystal Vesely
15,065 Points

How are we able to access the request object with no reference to it?

How are we able to call request.on(“error”, error => console.error(error)); when we are not passing that object into the function ? We are able to use the response object within the https.get(), from my understanding, because the response object is being passed into the callback. But within the getProfile function scope, the request object is not being passed in.

Crystal Vesely
Crystal Vesely
15,065 Points

Ok, so after thinking it through, I’m realizing the https.get() is a request, which will have a request object attached to it. It’s passing in the response object to the handler. But I am still needing some clarity on how you can call on the request object. Is the https.get() the reference? And anytime we call on the request within this function, it will always reference this https.get()?

I maybe getting confused, because I took the express and creating a node application training first before this training, and we always passed in both the request and response objects before calling on them.

1 Answer

Steven Parker
Steven Parker
241,958 Points

You don't need to pass the request object as an argument because you're calling a method of that object. So the object itself is always available from within that context as "this".