Remember how we talked about the fs module for Node in the introduction? We saw that it was capable of reading html and plain text–however fs is capable of so much more.
There are a multitude of things node’s file system module can do. Tt’s main uses include:
We’ve already somewhat covered how to read files within our previous http module demo! Now why don’t we look into how to create files using fs.
Now that we know of the primary uses for Node’s file system (fs), let’s get started with something simple; making a file!
Let’s start off by importing our module into our app,js file. If you remember from last time, we do that with the const fs = require(fs); command.
This includes the fs module in our node app and allows us to work with the files!
Now that we’ve done this, the rest is pretty straightforward.
We start off by first calling a method from the fs module called fs.writeFile(). The brackets here take up 3 different parameters;