read html file node js code example
Example 1: javascript write to file
<script>
const fs = require('fs')
let data = "Learning how to write in a file."
fs.writeFile('Output.txt', data, (err) => {
if (err) throw err;
})
</script>
Example 2: read html file node js
const http = require("http");
const fs = require("fs");
const hostname = "127.0.0.1";
const port = 3000;
const files = fs.readFileSync("new.html");
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
res.end(files);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
console.log("Done")
});