FAQ: Setting up a Server with HTTP - Interacting with Another Backend API

This community-built FAQ covers the “Interacting with Another Backend API” exercise from the lesson “Setting up a Server with HTTP”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Node.js

FAQs on the exercise Interacting with Another Backend API

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Terrible exercise. Steps 1 & 2: Half of the code the learner is supposed to write themselves is already half-written but some of it needs to be rewritten in some way, super confusing. Steps 3 & 4 assume the learner knows or somehow guessed from the previous section how to listen to a data and end events. Step 5 was impossible to pass even if my code was identical to the solution, which I had to check for each step given how badly written the instructions were. It’s almost impossible to understand at which moment we’re supposed to stop writing the code for a step in order to validate it. So if you write ‘too much’ instead of a partial code block, the step can be validated, but then you also have no clue what to do in the next one, since you’ve already written the full answer and yet the next step is still not validated. I really wish Codecademy would take feedback from a user who reads this lesson for the first time before going into designing such exercises.

11 Likes

I’m totally agree with you!

This exercise is pretty poorly constructed for the reasons mentioned by other users.

1 Like

in step 5 i replaced my entire code through copy & paste with the full given solution from (view solution) and it still failed. lol

2 Likes

Terrible exercise. Hints are not that detailed and the steps assume that a first-time learner knows everything. This SETTING UP A HTTP SERVER section is the worst section I encountered in my time with Codecademy. Everything assumes we know all and the code results are bugged. Nothing works until I click replace my code with the solution. I hope Codecademy fixes this whole section. This section is totally not for new learners. It’s bugged in one word.

2 Likes

Yup. I’ll second the emotion here. Again. Your Learning JavaScript unit is polished. So much so I bit the hook. Now I’m on the hook but I still need to learn. :frowning:

3 Likes

In the handleGetRequest function while creating a request I am seeing that we can use response.on to chunk the data and the next step, but according to my understanding .on is only valid on the event emitter instance. My query is, is the response argument an event emitter instance, if so then how would you know what is an event emitter instance and what is not? The reference to the code is below, please help!!

const request = http.request(options, response => {

let data = '';

// Aggregate data chunks as they come in from the API

response.on('data', (chunk) => {

  data += chunk;

}); 

// Handle the end of the request

response.on('end', () => {

  console.log("Retrieved Data:", data);

  res.end(data);

});
});

1 Like

I did the exact same thing. The javascript course was so well polished - even their command line course was fantastic, but this one has had… Issues

To anyone at Codecademy HQ who reads this: please sir, may I have my certificate? I’m willing to do the work, but it isn’t working…

2 Likes

Ok, seems like the problem is permissions, codecademy won’t let its own virtual env access the json contents it’s suppossed to get in this excercise. I just finished this lesson by doing this:

const jsonFile =
{
“id”: 25,
“firstName”: “John”,
“lastName”: “Johnson”,
“created”: “01-01-2001”,
“updated”: “06-24-2021”,
“phone”: “5555555555”,
“address”: “123 Generic St”,
“city”: “Smallville”,
“zipCode”: “55555”
};

  res.end(JSON.stringify(jsonFile));

Did you make a seperate json file and import it as when i try add your code it doesnt work.

HAve you had any luck with this?

1 Like

Did you ever find a solution to this?

1 Like

I have! I pasted in their solution and it is now working

Just paste this instead of res.end(data). paste the entire code, including the json object.

2 Likes

Thanks. I hope a portion of my subscription money can go to you. As I haven’t heard any help from Codecademy directly

1 Like

This is a terribly implemented lesson. The first step leaves out guiding the learner to add headers to the options model should be:

headers: { 'Content-Type': 'application/json' }

Secondly, this lesson just doesn’t work. Step 5 will never validate. Here are the steps I took to prove this:

  1. go through the lesson and bang my head on the wall because the last step won’t validate.
  2. Click “View solution” and verify that my solution matches verbatim.
  3. Finally click “Replace with Solution” and let step 5 pass.
  4. Re-do the lesson with the same results, this time copy the solution from the “View Solution” code and paste it in at step 1.
  5. Check work and validate all steps except step 5.

If you’re having problems with this lesson I suggest verifying your code is similar to the solution, replace it with the solution, and move on. I wasted hours on this.

2 Likes

this exercise is buggy. In the given solution, within the request callback function there is a variable called “res” that is never defined. My solution should be working fine, however it failed step 5. I then the code for step 5 into my solution and it still failed. It only worked when I opted to settle for the given solution. Also getting error messages for using different quotation style is annoying

1 Like

If you mean res.end(), then res is a response object from parameter of the callback function in createServer().
It is response that client will receive. When we run res.end() we end response message and send it to the client.

2 Likes

Yes, I know. But, that’s not the issue I’m referring to.