Step 5

Update the server.js file as follows:

const fs = require("fs");

fs.readFile("./index.html", "utf8", (err, files) => {
  console.log(err ? err : files);
});

Save the file and run it:

node server.js

You should see the entire content of index.html printed out to the console!

So, using Node, we can communicate with the file system. This is not possible in the browser! Now that we can read the content of index.html file, if we could only send that content over an HTTP response, we could set up our very own server.

Node has another module called http. It provides functionality for running HTTP servers and making HTTP requests! We'll see that next.