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

366
Views
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 answers
Answer question

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 Report
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!