i am currently learning node js
and I am getting
ReferenceError: readFile is not defined
after typing node . in the terminal
here is the code
const express = require("express");
const app = express();
app.get("/", (request, response) => {
readFile("./home.html", "utf8", (err, html) => {
if (err) {
response.status(500).send("sorry, out of order");
}
response.send(html);
});
});
app.listen(process.env.PORT || 3000, () =>
console.log("http://localhost:3000")
);
2
Answers
You need to import file system module:
In nodeJS if you want to do operation(Read, Write etc.) on files you have to use file system module provided by nodeJS.
Before using this module you have to import(ES6) or require it.
You can take reference from below how to use file system in node js