Creating folder and files using node js

share link

by shivanisanju03 dot icon Updated: Mar 21, 2023

technology logo
technology logo

Guide Kit Guide Kit  

We can create files and folder using node js by using fs.Access() and its promise-base fsPromises.access() counter part) to know whether the folder exists and also if Node.js can access it with permissions 


There are methods in file system module to create new files, they are:

  • fs.appendFile()
  • fs.open()
  • fs.writeFile()


To create a new folder , we can use fs.mkdir() or fs.mkdirSync or fsPromises.mkdir() .

Fig: Preview of the output that you will get on running this code from your IDE.

Code

Instructions


Follow the steps carefully to get the output easily.

  1. Install Visual Studio Code on your computer.
  2. create a new file using .js extension
  3. Copy and paste the code
  4. Save and rum the code to get output in the output terminal


I found this code snippet by searching for ' Creating folder , files using Node Js ' in kandi. You can try any such use case!

Environment Tested


I tested this solution in the following versions. Be mindful of changes when working with other versions.

  1. The solution is created and tested in Visual Studio Code 1.74.1.


Using this solution, we are able to create folder files using node js with simple steps. This process also facilities an easy way to use, hassle-free method to create a hands-on working version of code which would help us to create folder files using node js

Support


  1. For any support on kandi solution kits, please use the chat
  2. For further learning resources, visit the Open Weaver Community learning page.