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

143
Visualizações
Append child to html before sending to the client in SSR App

Actually I am using node js to implement SSR in my app.In server side rendering, html is prepared inside the server dynamically and updated.I want to update my html root element in the server using a js file but before sending it to the client. but when i tried it the js file is executing in the client. i want to execute it in the server and then append child to the html and then send that html file. Anyone help if it a wrong method and if not how can i do it

//my app.js
const express = require('express');
const app = express();
const path= require('path');
const cors = require('cors');

// const {sourceHTML} =require('./middlewares/fileHandler');

//for rendering css through the server we use app.use()
app.use(express.static(__dirname));
app.use(cors());



app.listen(3000,()=>{
    console.log("application started and running on port 3000")
});
app.get("/",(req,res)=>{
    res.status(200).sendFile(__dirname+'/html/home.html')
})

my home.html

  <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>home</title>
    </head>
    <body>
        <div id="root"></div>
    </body>
    </html>

so basically i want to edit html file from a js file so to access that html i have to use script tag inside html but problem happens that the script tag is parsed to the client so actually i want to execute that script at the server side before sending.

about 4 years ago · Juan Pablo Isaza
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