0

Using express js, i want to render json that has been produced by my to ejs file.

here is my controller that produce json

const getAllQuotes = asyncWrapper(async (req, res) => {
  const quotes = await qSchema.find({});
  res.status(200).json({ quotes });
});

I want to pass the JSON from controller to my router below, then what my router does is bring the data and show the data to admin page

adminRoute.get('/', async (req, res) => {
  //what should i type here?
        res.render("admin")
})

or maybe my question is about how the data can be thrown/passed in between js file

1 Answer 1

2

Don't make HTTP requests from your server back to your server.

You have a function that gets your data. Use that function.

adminRoute.get('/', async (req, res) => {
    const quotes = await qSchema.find({});
    res.render("admin", { quotes });
})
Sign up to request clarification or add additional context in comments.

1 Comment

I understand now, or it might be better if my router do this -> adminRoute.get('/').get(getAllQuotes); and then do fetch('') at the frontend. thankyou for the answer.

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.