Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda