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

191
Views
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
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!