Question: Activity 6 : File Functions in Nodejs fs module The following functions are available to write text to a file. fs . writeFileSync ( file

Activity 6: File Functions in Nodejs fs module
The following functions are available to write text to a file.
fs.writeFileSync(file, data[, options])
fs.appendFileSync (file, data[, options])
fs.readFileSync(path[, options])
Click on each function and read about it in the Nodejs documentation. In this activity you can
ignore the [options] parameter and work only with the path and data parameters
1. Add any dependencies required.
2. Extract the name of the folders in __dirname and write them one by one to a text file
called fileWrite.txt using the fs.writeFileSync(file, data[,
options]) function.
3. Extract the name of the folders in __dirname again nd write them one by one to a text file
called fileAppend.txt using the fs.appendFileSync(file, data[,
options]) function.
4. Open the two files that you have created and note the difference.
5. Recreate the fullpath name again by reading the folder names from fileAppend.js
using fs.readFileSync(path[, options]) function. (Hint use the
replaceAll() method for strings and path.sep from the path module to separate the
folder names)
6. Print the recreated full path to the console

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!