Getting ReferenceError: readFile is not defined

Advertisements

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")
);


>Solution :

You need to import file system module:

const fs = require('fs');
// ...

fs.readFile('...')

Leave a ReplyCancel reply