Node.js File System Module

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Create Files

The File System module has [ methods ] for creating new files: fs.appendFile() fs.open() fs.writeFile()

Update Files: fs.writeFile()

The fs.writeFile() method replaces the specified file and content:

Update Files

The File System module has methods for updating files: fs.appendFile() fs.writeFile()

Node.js as a File Server

The Node.js file system module allow you to work with the file system on your computer. To include the File System module, use the require() method:

fs.appendFile() method

The fs.appendFile() method appends specified content to a file. If the file does not exist, the file will be created:

Update Files: fs.appendFile()

The fs.appendFile() method appends the specified content at the end of the specified file:

fs.open() method

The fs.open() method takes a "flag" as the second argument, if the flag is "w" for "writing", the specified file is opened for writing. If the file does not exist, an empty file is created:

Read Files

The fs.readFile() method is used to read files on your computer. Create a Node.js file that reads the HTML file, and return the content:

fs.writeFile() method

The fs.writeFile() method replaces the specified file and content if it exists. If the file does not exist, a new file, containing the specified content, will be created:

Delete Files

To delete a file with the File System module, use the fs.unlink() method. The fs.unlink() method deletes the specified file:

Rename Files

To rename a file with the File System module, use the fs.rename() method. The fs.rename() method renames the specified file:


Kaugnay na mga set ng pag-aaral

Determine Meaning: Words and Phrases

View Set

4 - Enhanced Entity..Relationship and UML Modeling

View Set