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

192
Visualizações
Serve a web app using preact package with nodejs

I have an electron app where i use preact package to create components and serve them in an index.html and i want to turn it to a web app my file structure is

  • -- src/
  • ---- workers/
  • ---- components/
  • ---- index.js (rendering the div#root)
  • -- index.html (with div#root and script src='src/index.js')

the js files contain nodejs code i tried to create a root file index.js with a server pointing to index.html but the js inside src/ doesn't work

index.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>title</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
  <div id="root"></div>
  <script src="./src/index.js"></script>
</body>
</html>

src/index.js:

const { render, h } = require("preact");
const App = require("./components/App");

const rootEl = document.getElementById("root");
render(h(App, { rootEl }), rootEl);

i tried this:

const path = require("path");
const express = require("express");

const app = express();
app.use(express.static(__dirname));

app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname, '/index.html'));
  });

app.listen(process.env.PORT || 4433, () => {});
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