Click here to Skip to main content
15,300,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
router.get("/GetCategories", (req, res) => {
  console.log("again");
  category.find((err, docs) => {
    if (!err) {
      res.render("Category", {
        viewTitle: req.viewTitle,
        list: docs,
      });
    } else {
      console.log("Error in retrieving Category :" + err);
    }
  });
});
I want to call above api route "/GetCategories" from inside below nodejs application route
JavaScript
let categoryapi = require("../api/categories");

router.get("/GetCategoriesfromapi", async (req, res) => {
  let result = categoryapi.GetCategories;
  var url = categoryapi + "/GetCategories";
  let options = {
    url: url,
  };
  await request(options, function (err, data) {
    res.send(data);
  });
  // res.render("Category", { list: result });
});


What I have tried:

i tried to use categoryapi as method but its not working.
Posted
Updated 24-Sep-20 22:36pm
v2
Comments
Sandeep Mewara 25-Sep-20 1:49am
   
https://stackoverflow.com/questions/39047270/express-call-get-method-within-route-from-another-route

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