| Folders Node.js part2
Folders Node.js Part2
Here in this chapter we will read the content of a directory or folder. And here we will do different operation on the folder and files. We use fs.readdir() or fs.readdirSync() or fsPromises.readdir() to read the contents of a directory. And below code reads the content of a folder, files and subfolders and then returns their relative path. Below is the code to return the all files in some specific folder here we use two require first is to get fs module and second is for Path.
Here in below code we have use readdirSync to check all files and name the file as foldertest.js.
To view the code
Download Code
And below is the folder and its files details.
Now we open the node.js command prompt and run the below command to execute the command
node foldertest.js
And output of above command is given below:-
| | |