Click here to Skip to main content
15,743,544 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I am having a problem with my get request with nodejs, what is required as instruction is "
write a program to perform a GET request on the route and then print to the console the hobbies property in the following format: ITEM1, ITEM2, ...

// Output example expected

What I have tried:

<pre>const https = require('https');

(res) => {
  res.on('data', (d)=> {
    bv = JSON.parse(d.toString());
    console.log("Hobbies", bv.hobbies);
  }).on('error',(e)=> {


// output is incorrect as it prints
Hobbies [ 'running', 'coding', 'camping' ]
Updated 28-Feb-23 19:48pm

1 solution

As per my message from yesterday, you need to do your research first.

There is absolutely nothing wrong with your code when it returns -
Hobbies [ 'running', 'coding', 'camping' ]

Why, just paste the GET THE DATA FROM ARRAY SHOWN AT - [^] into your browser and this is the data shown -
{"name":"John Smith","age":25,"hobbies":["running","coding","camping"]}
Share this answer
Gcobani Mkontwana 1-Mar-23 2:58am    
@Andre Oosthuizen i wonder why from the editor when it compiles that my inputs are incorrect
Andre Oosthuizen 1-Mar-23 3:06am    
I cannot answer that as there are way too many variables at play. One will need to check set-up, controllers, API's, actual code etc etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900