| Folders in Node.js
Folders in Node.js
When we say about the folders handling in Node.js, we need to use the fs core module and this module also provide many handy methods to work with folders. Here in this chapter we try to cover some operations that we can do on folders and files.
Check folder exists or not
Well to check the folder you need to use fs.access() and its promise based fsPromises.access() counterpart to check the folder exists and Node.js can access it with its permissions.
Create a new folder
Well we can use fs module to create a folder, we use fs.mkdir() or fs.mkdirsync() or fsPromises.mkdir() to create a new folder.
We will create the file name createdirectory.js and run the code in node.js by below command
To view the file
Download Code
node createfolder.js
once we run above command it will check if the folder exist or not if not then it will create the test folder. | | |