Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

368
Vistas
How can I import a HTML file into Node.js?

So I'm trying to see how to import HTML into my Node.js file. The HTML file is named index.html and the JS is named script.js. I was trying to append "Hello World!" but it only says "Node.js Stuff"

Here is what I've tried:

var http = require('http');
var fs = require('fs');

http.createServer(function (req, res) {
    fs.readFile('index.html', function(data) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(data);
        res.write("Hello World!");
        res.end();
    });
}).listen(8080);

and this is the HTML file:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>replit</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <h1 class = "heading">Node.js Stuff</h1>
</body>

</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Install express:

npm i express

Node.js:

const express = require("express")
const app = express()
app.use(express.static(__dirname)
app.get("/",(req,res)=>{
    res.sendFile("index.html")
}
app.listen(3000,()=>{console.log("Started")})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda