The file system module, or simply fs
, allows you to access and interact with the file system on your machine.
Using the fs
module, you can perform actions such as:
This article will teach you the most common and useful fs
methods. Without further ado, let’s see what those methods are.
The file system module is a core Node.js module. That means that you do not have to install it. The only thing you have to do is import the fs
module into your file.
Thus, add the following line at the top of your file:
const fs = require('fs');
Now you can call any method from the file system module by using the prefix fs
.
Alternatively, you can import only the methods you want from the fs
API as follows:
const { writeFile, readFile } = require('fs');
However, in this tutorial, you will see the first option used — importing the whole fs
module.
#react #javascript #angular #nodejs #node