Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting ReferenceError: readFile is not defined

i am currently learning node js
and I am getting

ReferenceError: readFile is not defined

after typing node . in the terminal

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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('...')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading