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!
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

barak ben ishay
1,951 Pointswhy to store https.get () inside a request const in node js?
const https = require (https
);
const username = chalkers
;
//* here is the problem
const request = https.get(https://teamtreehouse.com/${username}.json
, response => {
console.log(response.statusCode);
});
3 Answers

Steven Parker
225,770 PointsThe ClientRequest object represents the request created by the "https.get" and is used to establish handlers to determine the status of the request and and to receive incoming data.
For more information, see the documentation page.

barak ben ishay
1,951 Pointslook at this : in simple js const name = "barak"; , it dosent do anything , only when i write name in the console it return the value barak, here in node js when i store the request in a const isnt it to be the same thing???

barak ben ishay
1,951 PointsSteve my problem is in clear understanding in the syntax , once we store a chanck of code inside of a variable, as shown here , We need to use it , it doesn’t helped with jest storing it

Steven Parker
225,770 PointsSee the additional comment I added to my answer.
Steven Parker
225,770 PointsSteven Parker
225,770 PointsIt sounds like you may be confused with how a "const" object can reflect any changes. But "const" doesn't mean the object itself cannot change, only that the variable cannot be changed to refer to a different object.
Steven Parker
225,770 PointsSteven Parker
225,770 PointsThe callback in the "get" is often all that is needed, but you can use the stored request if required. For example, you could use it to create an error handler: