Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Get the html source of a rendered ejs as string

I have this piece of code inside a controller:

exports.getintroDetails = async (req, res) => {
    try {
      const details = await IntroModel.find();
      return res.render("final", { details , user:req.user });
    } catch (error) {
      console.log(error.message);
    }
};

This code, as expected, renders the final.ejs file with the given data.

But instead, I want to show raw html which we get after rendering final.ejs with the given data. Is there any way to store the raw html as a string instead of rendering it?

So, instead of:

return res.render("final", { details , user:req.user });

I want something like this:

return res.send( view-source( res.render("final", { details , user:req.user }) ) );

Is there any function like view-source() as described above?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to docs you can provide a callback which will be executed with the rendered html. When the callback is provided the response won't automatically be made.

exports.getintroDetails = async (req, res) => {
    try {
      const details = await IntroModel.find();
      return res.render("final", { details , user:req.user }, (err, html) => {

        console.log('rendered html!', html)

        // now, the response has to be made manually.
        res.status(200).send(html)
      });
    } catch (error) {
      console.log(error.message);
    }
};

It is also possible, to render it using app.render() for only receiving the html.

From the docs

Think of app.render() as a utility function for generating rendered view strings. Internally res.render() uses app.render() to render views.

app.render('final', function (err, html) {
  // ...
})

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!