0

I have a controller where I am trying to return a response to the user but it's unable to send response and value is showing in console.

Below is my code:

const hubHome = (req,res) => {

  const hubId = req.params.hubId;

  fetchData(hubId);
}

const fetchData = (id) => {
  console.log(`Hub id is ${id}`);
  return res.status(200).send(`Hub id is ${id}`);
}

module.exports = hubHome; 

What am I missing?

1 Answer 1

1

Currently, the res object is not within the scope of fetchData. To fix this, add another parameter to fetchData.

const hubHome = (req,res) => {

  const hubId = req.params.hubId;

  fetchData(hubId, res);
}

const fetchData = (id, res) => {
  console.log(`Hub id is ${id}`);
  return res.status(200).send(`Hub id is ${id}`);
}

module.exports = hubHome;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it worked i havn't passed res as a parameter in my function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.